N = int(input())
S = [int(input()) for _ in range(N)]
#print(S)

s = ()
nex = 1

for i in range(N):
    #print(S[nex-1])
    nex = S[nex-1]
    if nex == 2:
        print(i+1)
        break
    if i == N-1:
        print(-1)
40ed7066ce047c21a177da224206aa433101efef
<mask token>

<mask token>
for i in range(N):
    nex = S[nex - 1]
    if nex == 2:
        print(i + 1)
        break
    if i == N - 1:
        print(-1)

N = int(input())
S = [int(input()) for _ in range(N)]
s = ()
nex = 1
for i in range(N):
    nex = S[nex - 1]
    if nex == 2:
        print(i + 1)
        break
    if i == N - 1:
        print(-1)

N = int(input())
S = [int(input()) for _ in range(N)]
#print(S)

s = ()
nex = 1

for i in range(N):
    #print(S[nex-1])
    nex = S[nex-1]
    if nex == 2:
        print(i+1)
        break
    if i == N-1:
        print(-1)