import sys

input = sys.stdin.readline



n = int(eval(input()))

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

count,light = 1,buttons[0]

while light != 2 and count<n:

    count,light = count+1,buttons[light-1]

print((count if count<n else -1))
import sys

input = sys.stdin.readline



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

n = buttons[0]

count,light = 1,buttons[1]

while light!=2 and count<n:

    count,light = count+1,buttons[light]

print((count if count<n else -1))
import sys

input = sys.stdin.readline
n = int(eval(input()))
buttons = [int(eval(input())) for n in range(n)]
count, light = 1, buttons[0]
while light != 2 and count < n:
    count, light = count + 1, buttons[light - 1]
print((count if count < n else -1))

import sys

input = sys.stdin.readline
buttons = list(map(int, sys.stdin))
n = buttons[0]
count, light = 1, buttons[1]
while light != 2 and count < n:
    count, light = count + 1, buttons[light]
print((count if count < n else -1))

-n = int(eval(input())) -buttons = [int(eval(input())) for n in range(n)] -count, light = 1, buttons[0] +buttons = list(map(int, sys.stdin)) +n = buttons[0] +count, light = 1, buttons[1] -    count, light = count + 1, buttons[light - 1] +    count, light = count + 1, buttons[light]