Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

pushed = deque([1])
button = 1

for _ in range(n):
    if a[button] in pushed:
        print(-1)
        break
    pushed.append(a[button])
    button = a[button]
    if button == 2:
        print(len(pushed) - 1)
        break

Fixed submission:
import sys

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

button = 1
count = 0

for _ in range(n):
    if button == 2:
        print(count)
        break
    button = a[button]
    count += 1

if count == n:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

pushed = [1]
button = 1

for _ in range(n):
    if a[button] in pushed:
        print(-1)
        break
    pushed.append(a[button])
    button = a[button]
    if button == 2:
        print(len(pushed) - 1)
        break

Fixed submission:
import sys

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

button = 1
count = 0

for _ in range(n):
    if button == 2:
        print(count)
        break
    button = a[button]
    count += 1

if count == n:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

pushed = [1]
button = 1

for _ in range(n):
    if a[button] in pushed:
        print(-1)
        break
    pushed.append(a[button])
    button = a[button]
    if button == 2:
        print(len(pushed) - 1)
        break

Fixed submission:
import sys

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

button = 1
count = 0

for _ in range(n):
    if button == 2:
        print(count)
        break
    button = a[button]
    count += 1

if count == n:
    print(-1)

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

pushed = [1]
button = 1

while button != 2:
    if a[button] in pushed:
        print(-1)
        break
    pushed.append(a[button])
    button = a[button]
else:
    print(len(pushed) - 1)

Fixed submission:
import sys

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

button = 1
count = 0

for _ in range(n):
    if button == 2:
        print(count)
        break
    button = a[button]
    count += 1

if count == n:
    print(-1)

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

pushed = [1]
button = 1

while button != 2:
    if a[button] in pushed:
        print(-1)
        break
    pushed.append(a[button])
    button = a[button]
else:
    print(len(pushed) - 1)

Fixed submission:
import sys

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

button = 1
count = 0

for _ in range(n):
    if button == 2:
        print(count)
        break
    button = a[button]
    count += 1

if count == n:
    print(-1)

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

pushed = [1]
button = 1

while button != 2:
    if a[button] in pushed:
        print(-1)
        break
    pushed.append(a[button])
    button = a[button]
else:
    print(len(pushed) - 1)

Fixed submission:
import sys

n = int(input())
a = [0] + [int(sys.stdin.readline()) for _ in range(n)]

button = 1
count = 0

for _ in range(n):
    if button == 2:
        print(count)
        break
    button = a[button]
    count += 1

if count == n:
    print(-1)