N = int(eval(input()))

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

x = 1

visited = set([1])

answer = 0



while True:

  x = a[x]

  if x in visited:

    answer = -1

    break

  visited.add(x)

  answer += 1

  if x == 2:

    break

    

print(answer)

N = int(eval(input()))

A = [int(eval(input())) for n in range(N)]

B = 0



for n in range(N):

  B = A[B]-1

  if B==1:

    print((n+1))

    exit()



print((-1))
N = int(eval(input()))
a = [0] + [int(eval(input())) for _ in range(N)]
x = 1
visited = set([1])
answer = 0
while True:
    x = a[x]
    if x in visited:
        answer = -1
        break
    visited.add(x)
    answer += 1
    if x == 2:
        break
print(answer)

N = int(eval(input()))
A = [int(eval(input())) for n in range(N)]
B = 0
for n in range(N):
    B = A[B] - 1
    if B == 1:
        print((n + 1))
        exit()
print((-1))

-a = [0] + [int(eval(input())) for _ in range(N)] -x = 1 -visited = set([1]) -answer = 0 -while True: -    x = a[x] -    if x in visited: -        answer = -1 -        break -    visited.add(x) -    answer += 1 -    if x == 2: -        break -print(answer) +A = [int(eval(input())) for n in range(N)] +B = 0 +for n in range(N): +    B = A[B] - 1 +    if B == 1: +        print((n + 1)) +        exit() +print((-1))