시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB111100.000%

## 문제

Alice and Bob are playing a cooperative game. They hold $b^p$ dollars between them, for given integers $b$ and $p$. Alice initially holds $x$ dollars, and Bob holds $b^p - x$ dollars. Alice and Bob want to consolidate their money, so one person holds all the money.

In each transaction, one player can choose to send the other player $b^y$ dollars, for some integer $y$ with $0 \le y < p$. But each player wants to initiate as few transactions as possible. They are willing to cooperate such that the player that initiates the most transactions (the busiest player), initiates as few as possible.

Alice and Bob want to know the fewest number of transactions that the busiest player needs to initiate to complete the transfer.

## 입력

The first line of input contains two integers $b$ ($2 \le b \le 100$) and $p$ ($2\le p\le 1000$), where $b$ is the base, and $p$ is the number of digits.

The next line contains $p$ integers $x_{p-1}, x_{p-2}, \ldots, x_0$, separated by spaces, with $0\le x_i<b$ and $0<x_{p-1}$. These are the base-$b$ digits of the value of $x$, with the most significant digit first. Specifically, $x=\sum_{0\le i<p} b^i x_i$. Note that they are given in order from the highest power to the lowest. For example, in the sample, 4 2 7 8 6 with $b=10$ represents the base $10$ number $42\,786$.

## 출력

Output a single integer, which is the minimum number of transactions the busiest player must initiate to transfer all the money to either Alice or Bob.

## 예제 입력 1

10 5
4 2 7 8 6


## 예제 출력 1

7


## 출처

• 문제를 만든 사람: Lewin Gan