n=int(eval(input()))

a=[]

cnt=0

now=0

for i in range(n):

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

flg=False

for i in range(n):

  if now==1:

    flg=True

    break

  now=a[now]

  cnt+=1

print((cnt if flg else -1))  
N,*a = list(map(int,open(0).read().split()))

a.insert(0,0)

flg = False

on = 1

cnt = 0

for i in range(N):

    on = a[on]

    cnt += 1

    if on == 2:

        print(cnt)

        exit()

print((-1))        
n = int(eval(input()))
a = []
cnt = 0
now = 0
for i in range(n):
    a.append(int(eval(input())) - 1)
flg = False
for i in range(n):
    if now == 1:
        flg = True
        break
    now = a[now]
    cnt += 1
print((cnt if flg else -1))

N, *a = list(map(int, open(0).read().split()))
a.insert(0, 0)
flg = False
on = 1
cnt = 0
for i in range(N):
    on = a[on]
    cnt += 1
    if on == 2:
        print(cnt)
        exit()
print((-1))

-n = int(eval(input())) -a = [] +N, *a = list(map(int, open(0).read().split())) +a.insert(0, 0) +flg = False +on = 1 -now = 0 -for i in range(n): -    a.append(int(eval(input())) - 1) -flg = False -for i in range(n): -    if now == 1: -        flg = True -        break -    now = a[now] +for i in range(N): +    on = a[on] -print((cnt if flg else -1)) +    if on == 2: +        print(cnt) +        exit() +print((-1))