N = int(eval(input()))

a = [int(eval(input())) for _ in range(N)]

b = [-1] * N

botan = a[0]



cnt = 0



for i in range(N):

    if botan == 2:

        print((cnt + 1))

        exit()

    cnt += 1

    botan = a[botan - 1]



print((-1))

from sys import stdin

input = stdin.readline

N = int(eval(input()))

a = [int(eval(input())) for _ in range(N)]

b = [-1] * N

botan = a[0]



cnt = 0



for i in range(N):

    if botan == 2:

        print((cnt + 1))

        exit()

    cnt += 1

    botan = a[botan - 1]



print((-1))

N = int(eval(input()))
a = [int(eval(input())) for _ in range(N)]
b = [-1] * N
botan = a[0]
cnt = 0
for i in range(N):
    if botan == 2:
        print((cnt + 1))
        exit()
    cnt += 1
    botan = a[botan - 1]
print((-1))

from sys import stdin

input = stdin.readline
N = int(eval(input()))
a = [int(eval(input())) for _ in range(N)]
b = [-1] * N
botan = a[0]
cnt = 0
for i in range(N):
    if botan == 2:
        print((cnt + 1))
        exit()
    cnt += 1
    botan = a[botan - 1]
print((-1))

+from sys import stdin + +input = stdin.readline