Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
x=[int(input()) for _ in range(N)]

#x=dict(zip(range(1,N+1),a))
#print(x)
route=[1,]
#for _ in range(N):
while 2 not in route:
  #print(x[route[-1]])
  if route[-1]==2:
    break
  elif x[route[-1]-1] not in route:
    route.append(x[route[-1]-1])
  else:
    print(-1)
    exit()
    
print(len(route)-1)

Fixed submission:
N=int(input())
x=[int(input()) for _ in range(N)]

on=1
ans=0
for _ in range(N):
  on=x[on-1]
  ans=ans+1
  if on==2:
    print(ans)
    exit()
  
print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
x=[int(input()) for _ in range(N)]

#x=dict(zip(range(1,N+1),a))
#print(x)
route=[1,]
for _ in range(N):
#while 2 not in route:
  #print(x[route[-1]])
  if route[-1]==2:
    break
  elif x[route[-1]-1] not in route:
    route.append(x[route[-1]-1])
  else:
    print(-1)
    exit()
        
print(len(route)-1)

Fixed submission:
N=int(input())
x=[int(input()) for _ in range(N)]

on=1
ans=0
for _ in range(N):
  on=x[on-1]
  ans=ans+1
  if on==2:
    print(ans)
    exit()
  
print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
x=[int(input()) for _ in range(N)]

#x=dict(zip(range(1,N+1),a))
#print(x)
route=[1,]
for _ in range(N):
#while 2 not in route:
  #print(x[route[-1]])
  if 2 in route:
    break
  elif x[route[-1]-1] not in route:
    route.append(x[route[-1]-1])
  else:
    print(-1)
    exit()
        
print(len(route)-1)

Fixed submission:
N=int(input())
x=[int(input()) for _ in range(N)]

on=1
ans=0
for _ in range(N):
  on=x[on-1]
  ans=ans+1
  if on==2:
    print(ans)
    exit()
  
print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
x=[int(input()) for _ in range(N)]

#x=dict(zip(range(1,N+1),a))
#print(x)
route=[1,]
while 2 not in route:
  #print(x[route[-1]])
  if x[route[-1]-1] not in route:
    route.append(x[route[-1]-1])
  else:
    print(-1)
    exit()
print(len(route)-1)

Fixed submission:
N=int(input())
x=[int(input()) for _ in range(N)]

on=1
ans=0
for _ in range(N):
  on=x[on-1]
  ans=ans+1
  if on==2:
    print(ans)
    exit()
  
print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
x=[int(input()) for _ in range(N)]

#x=dict(zip(range(1,N+1),a))
route=[1,]
while 2 not in route:
  #print(x[route[-1]])
  if x[route[-1]-1] not in route:
    route.append(x[route[-1]-1])
  else:
    print(-1)
    exit()
print(len(route)-1)

Fixed submission:
N=int(input())
x=[int(input()) for _ in range(N)]

on=1
ans=0
for _ in range(N):
  on=x[on-1]
  ans=ans+1
  if on==2:
    print(ans)
    exit()
  
print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=[int(input()) for _ in range(N)]

x=dict(zip(range(1,N+1),a))
#print(x)
route=[1,]
while 2 not in route:
  #print(x[route[-1]])
  if x[route[-1]] not in route:
    route.append(x[route[-1]])
  elif len(route)-1>N:
    print(-1)
    exit()
  else:
    print(-1)
    exit()
print(len(route)-1)


Fixed submission:
N=int(input())
x=[int(input()) for _ in range(N)]

on=1
ans=0
for _ in range(N):
  on=x[on-1]
  ans=ans+1
  if on==2:
    print(ans)
    exit()
  
print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=[int(input()) for _ in range(N)]

x=dict(zip(range(1,N+1),a))

route=[1,]
while 2 not in route:
  #print(x[route[-1]])
  if x[route[-1]] not in route:
    route.append(x[route[-1]])
  else:
    print(-1)
    exit()
print(len(route)-1)

Fixed submission:
N=int(input())
x=[int(input()) for _ in range(N)]

on=1
ans=0
for _ in range(N):
  on=x[on-1]
  ans=ans+1
  if on==2:
    print(ans)
    exit()
  
print(-1)