# ABC065B - Trained?

n = int(eval(input()))

lst = list(map(int, [input().rstrip() for _ in range(n)]))

button = lst[0]

count = 0

for _ in range(n):

    count += 1

    if button == 2:

        break

    button = lst[button - 1]

else:

    count = -1

print(count)
# ABC065B - Trained?

import sys

input = sys.stdin.readline



n = int(eval(input()))

lst = list(map(int, [input().rstrip() for _ in range(n)]))

button = lst[0]

count = 0

for _ in range(n):

    count += 1

    if button == 2:

        break

    button = lst[button - 1]

else:

    count = -1

print(count)
# ABC065B - Trained?
n = int(eval(input()))
lst = list(map(int, [input().rstrip() for _ in range(n)]))
button = lst[0]
count = 0
for _ in range(n):
    count += 1
    if button == 2:
        break
    button = lst[button - 1]
else:
    count = -1
print(count)

# ABC065B - Trained?
import sys

input = sys.stdin.readline
n = int(eval(input()))
lst = list(map(int, [input().rstrip() for _ in range(n)]))
button = lst[0]
count = 0
for _ in range(n):
    count += 1
    if button == 2:
        break
    button = lst[button - 1]
else:
    count = -1
print(count)

+import sys + +input = sys.stdin.readline