N = int(eval(input()))

a = {}

for i in range(N):

    a[i + 1] = int(eval(input()))



i = 1

cnt = 0

while True:

    next_i = a[i]

    cnt += 1

    if next_i < 1:

        print((-1))

        break

    elif next_i == 2:

        print(cnt)

        break



    a[i] = 0

    i = next_i
N = int(eval(input()))

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



pointer = a[0]

for i in range(N):

    if pointer - 1 == 1:

        print((i + 1))

        exit(0)

    pointer = a[pointer - 1]

print((-1))
N = int(eval(input()))
a = {}
for i in range(N):
    a[i + 1] = int(eval(input()))
i = 1
cnt = 0
while True:
    next_i = a[i]
    cnt += 1
    if next_i < 1:
        print((-1))
        break
    elif next_i == 2:
        print(cnt)
        break
    a[i] = 0
    i = next_i

N = int(eval(input()))
a = [int(eval(input())) for _ in range(N)]
pointer = a[0]
for i in range(N):
    if pointer - 1 == 1:
        print((i + 1))
        exit(0)
    pointer = a[pointer - 1]
print((-1))

-a = {} +a = [int(eval(input())) for _ in range(N)] +pointer = a[0] -    a[i + 1] = int(eval(input())) -i = 1 -cnt = 0 -while True: -    next_i = a[i] -    cnt += 1 -    if next_i < 1: -        print((-1)) -        break -    elif next_i == 2: -        print(cnt) -        break -    a[i] = 0 -    i = next_i +    if pointer - 1 == 1: +        print((i + 1)) +        exit(0) +    pointer = a[pointer - 1] +print((-1))