n = int(eval(input()))

a = []

l = [0]*(n + 1)

cnt = 0

now = 1



for i in range(n):

    a.append(int(eval(input())))



for i in range(n):

    cnt += 1

    now = a[now - 1]

    if now == 2:

        print(cnt)

        exit()



print((-1))
import sys

input = sys.stdin.readline



def main():

    n = int(eval(input()))

    a = []

    l = [0]*(n + 1)

    cnt = 0

    now = 1



    for i in range(n):

        a.append(int(eval(input())))



    for i in range(n):

        cnt += 1

        now = a[now - 1]

        if now == 2:

            print(cnt)

            exit()

    print((-1))



main()
n = int(eval(input()))
a = []
l = [0] * (n + 1)
cnt = 0
now = 1
for i in range(n):
    a.append(int(eval(input())))
for i in range(n):
    cnt += 1
    now = a[now - 1]
    if now == 2:
        print(cnt)
        exit()
print((-1))

import sys

input = sys.stdin.readline


def main():
    n = int(eval(input()))
    a = []
    l = [0] * (n + 1)
    cnt = 0
    now = 1
    for i in range(n):
        a.append(int(eval(input())))
    for i in range(n):
        cnt += 1
        now = a[now - 1]
        if now == 2:
            print(cnt)
            exit()
    print((-1))


main()

-n = int(eval(input())) -a = [] -l = [0] * (n + 1) -cnt = 0 -now = 1 -for i in range(n): -    a.append(int(eval(input()))) -for i in range(n): -    cnt += 1 -    now = a[now - 1] -    if now == 2: -        print(cnt) -        exit() -print((-1)) +import sys + +input = sys.stdin.readline + + +def main(): +    n = int(eval(input())) +    a = [] +    l = [0] * (n + 1) +    cnt = 0 +    now = 1 +    for i in range(n): +        a.append(int(eval(input()))) +    for i in range(n): +        cnt += 1 +        now = a[now - 1] +        if now == 2: +            print(cnt) +            exit() +    print((-1)) + + +main()