N = int(eval(input()))

a = [int(eval(input())) for i in range(N)]

isFound = False

ai = 1

for i in range(1, N + 1):

    ai = a[ai - 1]

#    print(f'a{i} = {ai}')

    if (ai == 2):

        isFound = True

        print(i)

        break

if (isFound is False):

    print((-1))

import sys



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

bot = N[1]



for i in range(N[0]):

    if bot == 2:

        print((i+1))

        break

    bot = N[bot]

else:

    print((-1))

N = int(eval(input()))
a = [int(eval(input())) for i in range(N)]
isFound = False
ai = 1
for i in range(1, N + 1):
    ai = a[ai - 1]
    #    print(f'a{i} = {ai}')
    if ai == 2:
        isFound = True
        print(i)
        break
if isFound is False:
    print((-1))

import sys

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

-N = int(eval(input())) -a = [int(eval(input())) for i in range(N)] -isFound = False -ai = 1 -for i in range(1, N + 1): -    ai = a[ai - 1] -    #    print(f'a{i} = {ai}') -    if ai == 2: -        isFound = True -        print(i) +import sys + +N = list(map(int, sys.stdin)) +bot = N[1] +for i in range(N[0]): +    if bot == 2: +        print((i + 1)) -if isFound is False: +    bot = N[bot] +else: