N = int(eval(input()))

a = [int(eval(input())) - 1 for _ in [0]*N]

cur = 0

cnt = -1

for i in range(N):

    cur = a[cur]

    if cur == 1:

        cnt = i + 1

        break

print(cnt)
import sys

e = list(map(int,sys.stdin))

cur = e[1]

for i in range(e[0]):

    if cur == 2:

        print((i + 1))

        break

    cur = e[cur]

else:

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

import sys

e = list(map(int, sys.stdin))
cur = e[1]
for i in range(e[0]):
    if cur == 2:
        print((i + 1))
        break
    cur = e[cur]
else:
    print((-1))

-N = int(eval(input())) -a = [int(eval(input())) - 1 for _ in [0] * N] -cur = 0 -cnt = -1 -for i in range(N): -    cur = a[cur] -    if cur == 1: -        cnt = i + 1 +import sys + +e = list(map(int, sys.stdin)) +cur = e[1] +for i in range(e[0]): +    if cur == 2: +        print((i + 1)) -print(cnt) +    cur = e[cur] +else: +    print((-1))