import sys



n = int(eval(input()))

a = [0] + [int(sys.stdin.readline()) for _ in range(n)]



button = 1



for i in range(n):

    if button == 2:

        print(i)

        break

    button = a[button]

else:

    print((-1))
import sys



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



button = 1



for i in range(n[0]):

    if button == 2:

        print(i)

        break

    button = n[button]

else:

    print((-1))
import sys

n = int(eval(input()))
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]
button = 1
for i in range(n):
    if button == 2:
        print(i)
        break
    button = a[button]
else:
    print((-1))

import sys

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

-n = int(eval(input())) -a = [0] + [int(sys.stdin.readline()) for _ in range(n)] +n = list(map(int, sys.stdin)) -for i in range(n): +for i in range(n[0]): -    button = a[button] +    button = n[button]