# coding: utf-8

import sys



N = int(eval(input()))

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



btn = 1

cnt = 0

for a in lst:

    btn = lst[btn-1]

    cnt += 1

    if btn == 2:

        print(cnt)

        sys.exit()

print((-1))
# coding: utf-8

import sys



N = int(eval(input()))

lst = [int(i) for i in sys.stdin]



btn = 1

cnt = 0

for a in lst:

    btn = lst[btn-1]

    cnt += 1

    if btn == 2:

        print(cnt)

        sys.exit()

print((-1))
# coding: utf-8
import sys

N = int(eval(input()))
lst = [int(eval(input())) for _ in range(N)]
btn = 1
cnt = 0
for a in lst:
    btn = lst[btn - 1]
    cnt += 1
    if btn == 2:
        print(cnt)
        sys.exit()
print((-1))

# coding: utf-8
import sys

N = int(eval(input()))
lst = [int(i) for i in sys.stdin]
btn = 1
cnt = 0
for a in lst:
    btn = lst[btn - 1]
    cnt += 1
    if btn == 2:
        print(cnt)
        sys.exit()
print((-1))

-lst = [int(eval(input())) for _ in range(N)] +lst = [int(i) for i in sys.stdin]