#R1019. [KBC002C] Sequence 4

[KBC002C] Sequence 4

Problem Description

Given a sequence aa of nn integers, you need to add digits at the end of the integers in order to make the sequence strictly increasing.

Adding digit tt (0t90\le t\le 9) at the end of a number xx can be represented as xx×10+tx\leftarrow x\times10+t.

Find the minimum number of digits to be added.

Constraints

For 70%70\% of the test cases:

  • 1n1041 \leq n \leq 10^4.
  • 1ai1091 \leq a_i \leq 10^9.
  • Score: 210210 pts.

For the remaining 30%30\% of the test cases:

  • 1n1051 \leq n \leq 10^5.
  • All the numbers in aa are equal.
  • Score: 9090 pts.

Input

The input is given in the following format from the standard input:

na1a2:ann\\a_1\\a_2\\:\\a_n

Output

Output the minimum number of digits to be added.

Sample Input

4
20
1
45
132

Sample Output

4

Explanation

After adding digits, the sequence becomes a=[20,199,459,1329]a=[20,199,459,1329].

Note that this is not the only possible solution.