Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
a=[int(input()) for i in range(N)]
b=[]
j=1
k=1
if 2 not in a:
    print(-1)
else:
    while j in range(1,N+1):
      if a[k-1] not in b:
         b.append(a[k-1])
         if a[k-1]==1:
                 break
         elif a[k-1]==2:
                 break
         else:
            j += 1
            k = a[k-1]
      else:
          break
    if 2 not in b:
        print(-1)
    else:
        print(len(b))

Fixed submission:
N=int(input())
a=[int(input()) for i in range(N)]
b=[]
j=1
k=1
c=1
if 2 not in a:
    print(-1)
else:
    while j in range(1,N+1):
         c += 1
         if a[k-1]==1:
                 print(-1)
                 break
         elif a[k-1]==2:
                 print(c-1)
                 break
         else:
            j += 1
            k = a[k-1]
    if c>=(N+1):
        print(-1)

Buggy python submission (verdict: Runtime Error):
N=int(input())
a=[int(input()) for i in range(N)]
b=[]
j=1
def c(j):
    if j==1:
        return 1
    else:
        return a[c(j-1)-1]
if 2 not in a:
    print(-1)
else:
    while j in range(1,N+1):
      if a[c(j)-1] not in b:
         b.append(a[c(j)-1])
         if a[c(j)-1]==2:
            break
         else:
            j += 1 
      else:
          break
    if 2 not in b:
        print(-1)
    else:
        print(len(b))


Fixed submission:
N=int(input())
a=[int(input()) for i in range(N)]
b=[]
j=1
k=1
c=1
if 2 not in a:
    print(-1)
else:
    while j in range(1,N+1):
         c += 1
         if a[k-1]==1:
                 print(-1)
                 break
         elif a[k-1]==2:
                 print(c-1)
                 break
         else:
            j += 1
            k = a[k-1]
    if c>=(N+1):
        print(-1)

Buggy python submission (verdict: Runtime Error):
N=int(input())
a=[int(input()) for i in range(N)]
b=[]
j=1
def c(j):
    if j==1:
        return 1
    else:
        return a[c(j-1)-1]
if 2 not in a:
    print(-1)
else:
    while a[c(j)-1] not in b:
        b.append(a[c(j)-1])
        if a[c(j)-1]==2:
            break
        else:
            j += 1
    if 2 not in b:
        print(-1)
    else:
        print(len(b))

Fixed submission:
N=int(input())
a=[int(input()) for i in range(N)]
b=[]
j=1
k=1
c=1
if 2 not in a:
    print(-1)
else:
    while j in range(1,N+1):
         c += 1
         if a[k-1]==1:
                 print(-1)
                 break
         elif a[k-1]==2:
                 print(c-1)
                 break
         else:
            j += 1
            k = a[k-1]
    if c>=(N+1):
        print(-1)

Buggy python submission (verdict: Runtime Error):
N=int(input())
a=[int(input()) for i in range(N)]
b=[]
def c(j):
    if j==1:
        return 1
    else:
        return a[c(j-1)-1]
j=1
if 2 not in a:
    print(-1)
else:
    while a[c(j)-1] not in b:
        b.append(a[c(j)-1])
        j += 1
    if 2 not in b:
        print(-1)
    else:
        print(b.index(2)+1)

Fixed submission:
N=int(input())
a=[int(input()) for i in range(N)]
b=[]
j=1
k=1
c=1
if 2 not in a:
    print(-1)
else:
    while j in range(1,N+1):
         c += 1
         if a[k-1]==1:
                 print(-1)
                 break
         elif a[k-1]==2:
                 print(c-1)
                 break
         else:
            j += 1
            k = a[k-1]
    if c>=(N+1):
        print(-1)