N = int(eval(input()))

a = []

for _ in range(N):

    a.append(int(eval(input())))

    

s = a[0]

cnt = 1



for i in range(N):

    if s == 2:

        print(cnt)

        exit()

    cnt += 1

    s = a[s-1]

    

print((-1))
import sys



N = int(eval(input()))

a = [int(i) for i in sys.stdin]

    

s = a[0]

cnt = 1



for i in range(N):

    if s == 2:

        print(cnt)

        exit()

    cnt += 1

    s = a[s-1]

    

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

import sys

N = int(eval(input()))
a = [int(i) for i in sys.stdin]
s = a[0]
cnt = 1
for i in range(N):
    if s == 2:
        print(cnt)
        exit()
    cnt += 1
    s = a[s - 1]
print((-1))

+import sys + -a = [] -for _ in range(N): -    a.append(int(eval(input()))) +a = [int(i) for i in sys.stdin]