P6740 [BalticOI 2014] Sequence (Day1)

Description

There are now $K$ consecutive positive integers. For each integer, you can only see one of its digits. Find the minimum possible value of the first number $N$.

Input Format

The first line contains an integer $K$, representing the length of the sequence. The second line contains $K$ integers, representing the digits you can see.

Output Format

Output one integer in a single line, representing the minimum possible value of $N$.

Explanation/Hint

#### Sample Explanation For sample $1$, the sequence that makes $N$ minimal is $47,48,49,50,51,52$, and the minimum value of $N$ is $47$. #### Constraints **This problem uses bundled testdata.** - Subtask 1 (9 pts): $N,K \le 1000$. - Subtask 2 (33 pts): $K \le 1000$. - Subtask 3 (25 pts): all given digits are equal. - Subtask 4 (33 pts): no special constraints. For $100\%$ of the data, $1 \le K \le 10^5$. **This problem enforces O2 optimization.** #### Notes Translated from [BalticOI 2014 Day1 C Sequence](http://www.boi2014.lmio.lt/tasks/sequence-en.pdf)。 Translated by ChatGPT 5