n = int(eval(input()))

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



x = 1

i = 0



while i < n and x != 2:

    x = a[x-1]

    i += 1



if x == 2:

    print(i)

else:

    print((-1))

import sys



n = int(eval(input()))

a = [int(x) for x in sys.stdin]



x = 1

i = 0



while i < n and x != 2:

    x = a[x-1]

    i += 1



if x == 2:

    print(i)

else:

    print((-1))

n = int(eval(input()))
a = [int(eval(input())) for i in range(n)]
x = 1
i = 0
while i < n and x != 2:
    x = a[x - 1]
    i += 1
if x == 2:
    print(i)
else:
    print((-1))

import sys

n = int(eval(input()))
a = [int(x) for x in sys.stdin]
x = 1
i = 0
while i < n and x != 2:
    x = a[x - 1]
    i += 1
if x == 2:
    print(i)
else:
    print((-1))

+import sys + -a = [int(eval(input())) for i in range(n)] +a = [int(x) for x in sys.stdin]