Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
  A.append(int(input())-1)
    
ans = -1
push = 0
count = []
 
for i in range(N+1):
 
    if A[push] == 1:
        ans = i+1
        break
        
    elif A[push] in count:
      break
      
    else:
      count.append(push)
      push = A[push]
        
print(ans)

Fixed submission:
n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = []
for i in range(N):
  A.append(int(input())-1)
    
ans = -1
push = 0
count = []
 
for i in range(N+1):
 
    if A[push] == 1:
        ans = i+1
        break
        
    elif A[push] in count:
      break
      
    else:
      　count.append(push)
        push = A[push]
        
print(ans)

Fixed submission:
n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
  A.append(int(input())-1)
    
ans = -1
push = 0
count = []

for i in range(N+1):

    if A[push] == 1:
        ans = i+1
        break
        
    elif A[push] in count:
      break
      
    else:
        push = A[push]
        count.append(push)
      
print(ans)

Fixed submission:
n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())

A = []
for _ in range(N):
  A.append(int(input())-1)

count = []
n = 0
for k in range(N+1):
  if A[n] == 1:
    break
 
  elif A[n] in count:
    ans = -1
    break
  
  else:
    count.append(A[n])
    ans = k+1
    n = A[n]
 
print(ans)


Fixed submission:
n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = []
for _ in range(N):
  A.append(int(input())-1)

count = []
n = 0
ans = 1
for _ in range(N+1):
  if A[n] == 1:
    break
 
  elif A[n] in count:
    ans = -1
    break
  
  else:
    count.append(A[n])
    ans += 1
    n = A[n]
 
print(ans)

Fixed submission:
n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

A = []
for _ in range(N):
  A.append(int(input())-1)

count = []
n = 0
ans = 1
for k in range(N+1):
  if A[n] == 1:
    break
 
  elif A[n] in count:
    ans = -1
    break
  
  else:
    count.append(A[n])
    ans += 1
    n = A[n]
 
print(ans)

Fixed submission:
n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for _ in range(N):
  A.append(int(input())-1)
#[int(input())-1]
 
count = []
n = 0
ans = 1
for k in range(N+1):
  if A[n] == 2-1:
    break
 
  elif A[n] in count:
    ans = -1
    break
  
  else:
    count.append(A[n])
    ans += 1
    n = A[n]
 
print(ans)

Fixed submission:
n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for _ in range(N):
  A.append(int(input())-1)
#[int(input())-1]
 
count = [-1]*N
n = 0
ans = 1
for k in range(N+1):
  if A[n] == 2-1:
    break
 
  elif A[n] in count:
    ans = -1
    break
  
  else:
    count[n] = A[n]
    ans += 1
    n = A[n]
 
print(ans)

Fixed submission:
n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
# A[0]
A = list(map(lambda x: int(x)-1, [input() for n in range(N)]))
#[int(input())-1]
 
count = [-1]*N
n = 0
ans = 1
for k in range(N+1):
  if A[n] == 2-1:
    break

  elif A[n] in count:
    ans = -1
    break
  
  else:
    count[n] = A[n]
    ans += 1
    n = A[n]
 
print(ans)

Fixed submission:
n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
# A[0]
A = [int(input())-1]
 
count = [-1]*N
n = 0
ans = 1
for k in range(N+1):
  if A[n] == 2-1:
    break
  
  elif A[n]+1 > len(A):
    for _ in range(A[n]+1 - len(A)):
      A.append(int(input()) -1)
    continue
  
  
  elif A[n] in count:
    ans = -1
    break
  
  else:
    count[n] = A[n]
    ans += 1
    n = A[n]
 
print(ans)

Fixed submission:
n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
# A[0]
A = [int(input())-1]
 
count = [-1]*N
n = 0
ans = 1
for k in range(N+1):
  if A[n] == 2-1:
    break
  
  if A[n]+1 > len(A):
    for _ in range(A[n]+1 - len(A)):
      A.append(int(input()) -1)
    continue
  
  n = A[n]
  if n in count:
    ans = -1
    break
  count[n] = n
  ans += 1
 
print(ans)

Fixed submission:
n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
# A[0]
A = [int(input())-1]

count = [-1]*N
n = 0
ans = 1
while A[n] != 2-1:
  
  if A[n]+1 > len(A):
    for _ in range(A[n]+1 - len(A)):
      A.append(int(input()) -1)
    continue
  
  n = A[n]
  if n in count:
    ans = -1
    break
  count[n] = n
  ans += 1

print(ans)

Fixed submission:
n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
#A = [0]*N
A = list(map(lambda x: int(x)-1, [input() for n in range(N)]))

count = [-1]*N
n = 0
ans = 1
while A[n] != 2-1:
  n = A[n]
  if n in count:
    ans = -1
    break
  count[n] = n
  ans += 1
  
print(ans)

Fixed submission:
n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [0]*N

for n in range(N):
  A[n] = int(input()) -1
  
count = [-1]*N
n = 0
ans = 1
while A[n] != 2-1:
  n = A[n]
  if n in count:
    ans = -1
    break
  count[n] = n
  ans += 1
  
print(ans)

Fixed submission:
n = int(input())
al = []
for i in range(n):
    a = int(input())
    al.append(a)
 
al.insert(0, 0)
ans = -1
push = 1
for i in range(1, n+2):
    light = al[push]
    push = light
    if light == 2:
        ans = i
        break
print(ans)