Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input())
    dict={}
    for i in range(n):
        dict[i] = int(input())

    list2=[]
    count = 0
    now =1
    for i in range(n):
        if now in list2:
            print(-1)
            break
        else:
            if dict[now-1] ==2:
                count+=1
                print(count)
                break
            else:
                list2.append(now)
                count+=1
                now = dict[now-1]

Fixed submission:
if __name__ == '__main__':
    n = int(input())
    dict={}
    for i in range(n):
        dict[i] = int(input())

    dict2={}
    count = 0
    now =1
    for i in range(n):
        if now in dict2:
            print(-1)
            break
        else:
            if dict[now-1] ==2:
                count+=1
                print(count)
                break
            else:
                dict2[now]=0
                count+=1
                now = dict[now-1]

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input())
    dict={}
    for i in range(n):
        dict[i] = int(input())

    list2=[]
    count = 0
    now =1
    for i in range(n):
        if now in list2:
            print(-1)
            break
        else:
            if dict[now-1] ==2:
                count+=1
                print(count)
                break
            else:
                list2.append(now)
                count+=1
                now = dict[now-1]

Fixed submission:
if __name__ == '__main__':
    n = int(input())
    dict={}
    for i in range(n):
        dict[i] = int(input())

    dict2={}
    count = 0
    now =1
    for i in range(n):
        if now in dict2:
            print(-1)
            break
        else:
            if dict[now-1] ==2:
                count+=1
                print(count)
                break
            else:
                dict2[now]=0
                count+=1
                now = dict[now-1]

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input())
    list =[]
    for i in range(n):
        list.append(int(input()))

    list2=[]
    count = 0
    now =1
    for i in range(n):
        if now in list2:
            print(-1)
            break
        else:
            if list[now-1] ==2:
                count+=1
                print(count)
                break
            else:
                list2.append(now)
                count+=1
                now = list[now-1]

Fixed submission:
if __name__ == '__main__':
    n = int(input())
    dict={}
    for i in range(n):
        dict[i] = int(input())

    dict2={}
    count = 0
    now =1
    for i in range(n):
        if now in dict2:
            print(-1)
            break
        else:
            if dict[now-1] ==2:
                count+=1
                print(count)
                break
            else:
                dict2[now]=0
                count+=1
                now = dict[now-1]

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input())
    list =[]
    for i in range(n):
        list.append(int(input()))

    list2=[]
    count = 0
    now =1
    while True:
        if now in list2:
            print(-1)
            break
        else:
            if list[now-1] ==2:
                count+=1
                print(count)
                break
            else:
                list2.append(now)
                count+=1
                now = list[now-1]

Fixed submission:
if __name__ == '__main__':
    n = int(input())
    dict={}
    for i in range(n):
        dict[i] = int(input())

    dict2={}
    count = 0
    now =1
    for i in range(n):
        if now in dict2:
            print(-1)
            break
        else:
            if dict[now-1] ==2:
                count+=1
                print(count)
                break
            else:
                dict2[now]=0
                count+=1
                now = dict[now-1]

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input())
    list =[]
    for i in range(n):
        list.append(int(input()))

    list2=[]
    count = 0
    now =1
    while True:
        if now in list2:
            print(-1)
            break
        else:
            if list[now-1] ==2:
                count+=1
                print(count)
                break
            else:
                list2.append(now)
                count+=1
                now = list[now-1]

Fixed submission:
if __name__ == '__main__':
    n = int(input())
    dict={}
    for i in range(n):
        dict[i] = int(input())

    dict2={}
    count = 0
    now =1
    for i in range(n):
        if now in dict2:
            print(-1)
            break
        else:
            if dict[now-1] ==2:
                count+=1
                print(count)
                break
            else:
                dict2[now]=0
                count+=1
                now = dict[now-1]