Lady Sequence#10495

Lady Sequence

1 second
256 megabytes
Hard

The lady wrote down a sequence of consecutive positive integers on a piece of paper. The first number in this sequence was . For instance, if n = 47 and k = 5, the sequence would be [47, 48, 49, 50, 51]. While she was at school, her younger sister played with the sequence and removed all but one digit from each number, resulting in a sequence of single digits.

When the lady returned from school, she was upset because she couldn't remember the starting number . Your task is to help her find the smallest possible from which the sequence could have started.

Input

The first line contains a single integer (1 \leq k \leq 10^5) — the number of numbers in the sequence.

The second line contains digits b_1, b_2, \dots, b_k (0 \leq b_i \leq 9) — the sequence of digits that the lady found when she returned from school.

Output

Output a single line with the answer — the smallest number from which the lady's sequence could have started.

Examples

Example 1

Loading
Loading

Note

For example, n = 47 results in the sequence [47, 48, 49, 50, 51, 52], from which the lady's younger sister could have removed digits to create the sequence of digits given in the example. Since no smaller will work, the answer is .

Scoring

  1. ( points): 1 \leq k \leq 1000, the correct answer does not exceed ;

  2. ( points): 1 \leq k \leq 1000;

  3. ( points): 1 \leq k \leq 10^5, all digits in the sequence are the same;

  4. ( points): 1 \leq k \leq 10^5.