- Time limit: 1.00 s
- Memory limit: 512 MB
Uolevi has bough a new board game: Ladders. The board has squares numbered . Number is written on square . Each of the numbers occurs exactly once in . For each pair of squares , there is a ladder starting from and ending in if is a multiple of .
When playing the game, a player can either move up one square or use one of the ladders that starts from the current square. All players start from square and their goal is to reach square . Uolevi wants to calculate the minimum number of moves needed to finish the game so that he can beat Maija every time they play.
Input
The first line contain a single integers . The second line contains integers .
Output
Print the minimum number of moves required to finish the game.
Constraints
- if
Example 1
Input:
10 8 10 3 6 5 1 4 7 2 9
Output:
3
Explanation:
The indices of the visited squares are:
We can do the last move since
Example 2
Input:
10 6 7 10 9 2 1 3 8 4 5
Output:
6
Example 3
Input:
1 1
Output:
0