Package for this problem was not updated by the problem writer or Codeforces administration after we’ve upgraded the judging servers. To adjust the time limit constraint, solution execution time will be multiplied by 2. For example, if your solution works for 400 ms on judging servers, then value 800 ms will be displayed and used to determine the verdict.

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

B. Find Marble

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputPetya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not.

First Petya puts a marble under the glass in position *s*. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position *p*_{1}, the glass from the second position to position *p*_{2} and so on. That is, a glass goes from position *i* to position *p*_{i}. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in.

After all shuffling operations Petya shows Vasya that the ball has moved to position *t*. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position *s* to position *t*.

Input

The first line contains three integers: *n*, *s*, *t* (1 ≤ *n* ≤ 10^{5}; 1 ≤ *s*, *t* ≤ *n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*_{1}, *p*_{2}, ..., *p*_{n} (1 ≤ *p*_{i} ≤ *n*) — the shuffling operation parameters. It is guaranteed that all *p*_{i}'s are distinct.

Note that *s* can equal *t*.

Output

If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1.

Examples

Input

4 2 1

2 3 4 1

Output

3

Input

4 3 3

4 1 3 2

Output

0

Input

4 3 4

1 2 3 4

Output

-1

Input

3 1 3

2 1 3

Output

-1

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Dec/14/2019 01:22:07 (e2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|