#T92. 奇怪的电梯

奇怪的电梯

Description

Each floor of the building can be accessed by the elevator, and there is a number Ki(0KiN)K_i (0 \leq K_i \leq N) on the ii-th floor (1 ≤ i ≤ N). The elevator has only four buttons: open, close, up, and down. The number of floors moved up or down equals the number on the current floor.

Of course, if the request cannot be satisfied, the corresponding button will not work. For example: 3 3 1 2 5 represents KiK_i (where K1=3K_1 = 3, K2=3K_2 = 3, etc.), starting from the first floor. On the first floor, pressing "up" will take you to the 4th floor, while pressing "down" will not work because there is no -2nd floor. So, what is the minimum number of button presses required to go from floor A to floor B?

Input Format

There are two lines of input. The first line contains three space-separated positive integers: N, A, B (1 ≤ N ≤ 200, 1 ≤ A, B ≤ N). The second line contains N space-separated positive integers representing KiK_i.

Output Format

A single line containing the minimum number of button presses. If it is impossible to reach, output -1.

5 1 5
3 3 1 2 5


3