Petya 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*<sub class="lower-index">1</sub>, the glass from the second position to position *p*<sub class="lower-index">2</sub> and so on. That is, a glass goes from position *i* to position *p*<sub class="lower-index">*i*</sub>. 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*.
The first line contains three integers: *n*, *s*, *t* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>; 1 ≤ *s*, *t* ≤ *n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*<sub class="lower-index">1</sub>, *p*<sub class="lower-index">2</sub>, ..., *p*<sub class="lower-index">*n*</sub> (1 ≤ *p*<sub class="lower-index">*i*</sub> ≤ *n*) — the shuffling operation parameters. It is guaranteed that all *p*<sub class="lower-index">*i*</sub>'s are distinct.

Note that *s* can equal *t*.
# # Next Round
# str1 = input()
# n, k = str1.split(' ')
# k = int(k)
# str2 = input()
# s = str2.split(' ')
# t = 0
# for i in range(0, len(s)):
#     if int(s[i]) >= int(s[k-1]) and int(s[i]) > 0:
#         t += 1
# print(t)

# # String Task
# str = input()
# str = str.lower()
# D = {'a': 1, 'e': 1, 'i': 1, 'o': 1, 'u': 1, 'y': 1}
# flag = 0
# for i in range(0, len(str)):
#     if str[i] not in D:
#         if flag == 0:
#             s = '.' + str[i]
#             flag = 1
#         else:
#             s = s + '.' + str[i]
# if flag == 1:
#     print(s)

# # bit++
# n = input()
# n = int(n)
# t = 0
# for i in range(0, n):
#     str = input()
#     for j in range(0, len(str)):
#         if str[j] == '+':
#             t += 1
#             break
#         if str[j] == '-':
#             t -= 1
#             break
# print(t)

# # Petya and strings
# str1 = input()
# str1 = str1.lower()
# str2 = input()
# str2 = str2.lower()
# c = 0
# for i in range(0, len(str1)):
#     temp = ord(str1[i]) - ord(str2[i])
#     if temp < 0:
#         c = -1
#         break
#     if temp > 0:
#         c = 1
#         break
# print(c)
#

# # Football
# str = input()
# n = 1
# flag = 0
# for i in range(0, len(str)):
#     if flag == 0:
#         temp = str[i]
#         flag = 1
#     else:
#         if temp == str[i]:
#             n += 1
#             if n >=7:
#                 break
#         else:
#             temp = str[i]
#             n = 1
# if n == 7:
#     print('YES')
# else:
#     print('NO')

# # Combination Lock
#
# n = input()
# n = int(n)
# str1 = input()
# str2 = input()
# temp = 0
# for i in range(0, n):
#     t1 = int(str1[i])
#     t2 = int(str2[i])
#     a = min(abs(t1 - t2), abs(t1 + 10 - t2))
#     m = min(a, abs(t2 + 10 - t1))
#     temp += m
# print(temp)

# buttons
# n = input()
# n = int(n)
# t = 0
# for i in range(1, n + 1):
#     t = t + (n - i) * i + 1
# print(t)
#

# Word Capitalization
# str = input()
# str1 = str[0].upper() + str[1:]
# print(str1)

# Beautiful Matrix
# m = 0
# n = 0
# for i in range(0, 5):
#     str = input()
#     for j in range(0, len(str)):
#         if str[j] == '1':
#             m = i + 1
#             n = j / 2 + 1
#             break
# t = abs(m - 3) + abs(n - 3)
# print(int(t))

# Stones on the Table
# n = int(input())
# str = input()
# t = 0
# temp = str[0]
# for i in range(1, n):
#     if temp == str[i]:
#         t += 1
#     temp = str[i]
# print(t)

# Find Marble
s1 = input()
n = int(s1.split()[0])
s = int(s1.split()[1])
t = int(s1.split()[2])
tmp = [0]
p = [0]
s2 = input()
for i in range(0, n):
    tmp.append(int(s2.split()[i]))
    p.append(0)

flag = 0
num = 0
if t not in tmp:
    k = -1
elif s == t:
    k = 0
else:
    q = 0
    while not tmp[s] == t:
        if q >= n:
            break
        q += 1
        num += 1
        if p[s] == 1:
            break
        p[s] = 1
        s = tmp[s]
    if tmp[s] == t:
        k = num + 1
    else:
        k = -1
print(k)

# Lucky Ticket
# n = int(input())
# s = input()
# t = [0]
# k = int(n/2)
# sum1 = 0
# sum2 = 0
# flag = 0
# for i in range(0, n):
#     t.append(int(s[i]))
# for i in range(1, n+1):
#     f1 = not t[i] == 7
#     f2 = not t[i] == 4
#     if f1 and f2:
#         str = 'NO'
#         flag = 1
#         break
#     if i <= k:
#         sum1 += t[i]
#     else:
#         sum2 += t[i]
# if flag == 0:
#     if sum1 == sum2:
#         str = 'YES'
#     else:
#         str = 'NO'
# print(str)

# One-dimensional Japanese Crossword
# n = int(input())
# s = input()
# flag = 0
# sum = 0
# l = []
# t = 0
# for i in range(0, n):
#     if flag == 0:
#         tmp = s[i]
#         if s[i] == 'B':
#             t += 1
#             sum += 1
#         flag = 1
#     else:
#         if s[i] == 'B':
#             if tmp == 'W':
#                 t += 1
#             sum += 1
#         else:
#             if tmp == 'B':
#                 l.append(sum)
#                 sum = 0
#     tmp = s[i]
# if not sum == 0:
#     l.append(sum)
#
# if t == 0:
#     print(0)
# else:
#     str1 = ''
#     for i in range(0, len(l)-1):
#         str1 = str1 + str(l[i]) + ' '
#     str1 = str1 + str(l[len(l)-1])
#     print(t)
#     print(str1)


# Airport
# s = input()
# m = int(s.split()[0])
# n = int(s.split()[1])
# s2 = input()
# t1 = []
# t2 = []
# maxs = 0
# mins = 0
# for i in range(0, n):
#     t1.append(int(s2.split()[i]))
#     t2.append(int(s2.split()[i]))
# for i in range(0, m):
#     maxs += max(t1)
#     p = t1.index(max(t1))
#     t1[p] = t1[p] - 1
#
#     mins += min(t2)
#     p = t2.index(min(t2))
#     t2[p] = t2[p] - 1
#     if t2[p] == 0:
#         t2[p] = float("inf")
# print(maxs, mins)




