PCK's mailbox is equipped with a special dial lock. The lock has a rotating dial with numbers from 0 to 9 in a clockwise direction. There is a red marker on the top of the dial, and when the numbers match the marker, it sounds like a click once.
This dial lock has a predetermined sequence of numbers as a secret code to open the lock. To open the lock, start with 0 aligned with the marker, and then turn the dial to align the numbers in the secret code with the marker in sequence. The lock can only be opened if the number of clicks before all the numbers are aligned is minimal.
For example, if your secret code number is 374, as shown in the figure, you can start with 0, turn counterclockwise to 3, then counterclockwise to 7, and finally clockwise to 4, for a total of 10 clicks. If you turn the dial in this way, the dial lock will open, because 10 is the minimum number of clicks when you turn the dial in the order of 3, 7, and 4.
Given a security code for a dial lock, create a program that calculates the number of clicks it takes for the lock to open when the number 0 is aligned with the marker.
Input is given in the following format.
$N$ $a_1$ $a_2$ ... $a_N$
In the first line, the number of digits in the sequence of the secret code $N$ ($1 \leq N \leq 1,000$) is given, and in the second line, the digits in the secret code $a_i$ ($0 \leq a_i \leq 9$) are given in order. The same number is never given consecutively. The first number $a_1$ is a number other than 0.
Output the number of times the sound is heard before the lock is opened on a single line.
3 3 7 4
10
4 1 2 3 9
7