def main():

    N = int(eval(input()))

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

    i = 1

    ans = 0



    for K in range(N):

        i = a[i-1]

        ans += 1

        if i == 2:

            return ans

    ans = -1

    return ans



print((main()))         

def main():

    N = int(eval(input()))

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

    cnt = 0

    tmp = 1

    while cnt<=100001:

        tmp = a[tmp-1]

        cnt += 1

        if tmp == 2:

            return cnt

        elif tmp == 1:

            return -1



    return -1



print((main()))

def main():
    N = int(eval(input()))
    a = [int(eval(input())) for _ in range(N)]
    i = 1
    ans = 0
    for K in range(N):
        i = a[i - 1]
        ans += 1
        if i == 2:
            return ans
    ans = -1
    return ans


print((main()))

def main():
    N = int(eval(input()))
    a = [int(eval(input())) for _ in range(N)]
    cnt = 0
    tmp = 1
    while cnt <= 100001:
        tmp = a[tmp - 1]
        cnt += 1
        if tmp == 2:
            return cnt
        elif tmp == 1:
            return -1
    return -1


print((main()))

-    i = 1 -    ans = 0 -    for K in range(N): -        i = a[i - 1] -        ans += 1 -        if i == 2: -            return ans -    ans = -1 -    return ans +    cnt = 0 +    tmp = 1 +    while cnt <= 100001: +        tmp = a[tmp - 1] +        cnt += 1 +        if tmp == 2: +            return cnt +        elif tmp == 1: +            return -1 +    return -1