Buggy python submission (verdict: Runtime Error):
n = int(input())
buttons = [0]
target_index = 0
for _ in range(n):
    num = int(input())
    buttons.append(num)

count = 0
next_index = 2
while count < n:
    if next_index < 1 or len(buttons) - 1 <= next_index:
        count = -1
        break

    prev_index = buttons.index(next_index)
    count += 1
    if prev_index == 1:
        break
    else:
        next_index = prev_index

print(count if count < n else -1)


Fixed submission:
n = int(input())
buttons = [0]
target_index = 0
for _ in range(n):
    buttons.append(int(input()))

count = 0
prev_index = 1
while count < n:
    if prev_index < 1 or len(buttons) <= prev_index:
        count = -1
        break

    next_index = buttons[prev_index]
    count += 1
    if next_index == 2:
        break
    else:
        prev_index = next_index

print(count if count < n else -1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
buttons = [0]
target_index = 0
for i in range(n):
    num = int(input())
    buttons.append(num)

count = 0
next_index = 2
while count < n:
    if next_index < 1 or len(buttons) - 1 <= next_index:
        count = -1
        break

    prev_index = buttons.index(next_index)
    count += 1
    if prev_index == 1:
        break
    else:
        next_index = prev_index

print(count if count < n else -1)


Fixed submission:
n = int(input())
buttons = [0]
target_index = 0
for _ in range(n):
    buttons.append(int(input()))

count = 0
prev_index = 1
while count < n:
    if prev_index < 1 or len(buttons) <= prev_index:
        count = -1
        break

    next_index = buttons[prev_index]
    count += 1
    if next_index == 2:
        break
    else:
        prev_index = next_index

print(count if count < n else -1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
buttons = [0]
target_index = 0
for i in range(n):
    num = int(input())
    buttons.append(num)

count = 0
next_index = 2
while count < n:
    if len(buttons) - 1 <= next_index <= 0:
        count = -1
        break

    prev_index = buttons.index(next_index)
    count += 1
    if prev_index == 1:
        break
    else:
        next_index = prev_index

print(count if count < n else -1)


Fixed submission:
n = int(input())
buttons = [0]
target_index = 0
for _ in range(n):
    buttons.append(int(input()))

count = 0
prev_index = 1
while count < n:
    if prev_index < 1 or len(buttons) <= prev_index:
        count = -1
        break

    next_index = buttons[prev_index]
    count += 1
    if next_index == 2:
        break
    else:
        prev_index = next_index

print(count if count < n else -1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
buttons = [0]
target_index = 0
for i in range(n):
    num = int(input())
    buttons.append(num)

count = 0
next_index = 2
while count < n:
    if len(buttons) - 1 <= next_index:
        count = -1
        break

    prev_index = buttons.index(next_index)
    count += 1
    if prev_index == 1:
        break
    else:
        next_index = prev_index

print(count if count < n else -1)


Fixed submission:
n = int(input())
buttons = [0]
target_index = 0
for _ in range(n):
    buttons.append(int(input()))

count = 0
prev_index = 1
while count < n:
    if prev_index < 1 or len(buttons) <= prev_index:
        count = -1
        break

    next_index = buttons[prev_index]
    count += 1
    if next_index == 2:
        break
    else:
        prev_index = next_index

print(count if count < n else -1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
buttons = [0]
target_index = 0
for i in range(n):
    num = int(input())
    buttons.append(num)

count = 0
next_index = 2
while count < n:
    if len(buttons) - 1 < next_index:
        count = -1
        break

    prev_index = buttons.index(next_index)
    count += 1
    if prev_index == 1:
        break
    else:
        next_index = prev_index

print(count if count < n else -1)


Fixed submission:
n = int(input())
buttons = [0]
target_index = 0
for _ in range(n):
    buttons.append(int(input()))

count = 0
prev_index = 1
while count < n:
    if prev_index < 1 or len(buttons) <= prev_index:
        count = -1
        break

    next_index = buttons[prev_index]
    count += 1
    if next_index == 2:
        break
    else:
        prev_index = next_index

print(count if count < n else -1)

Buggy python submission (verdict: Runtime Error):
n = int(input())
buttons = [0]
target_index = 0
for i in range(n):
    num = int(input())
    buttons.append(num)

count = 0
next_index = 2
while count < n:
    prev_index = buttons.index(next_index)
    count += 1
    if prev_index == 1:
        break
    else:
        next_index = prev_index

print(count if count < n else -1)

Fixed submission:
n = int(input())
buttons = [0]
target_index = 0
for _ in range(n):
    buttons.append(int(input()))

count = 0
prev_index = 1
while count < n:
    if prev_index < 1 or len(buttons) <= prev_index:
        count = -1
        break

    next_index = buttons[prev_index]
    count += 1
    if next_index == 2:
        break
    else:
        prev_index = next_index

print(count if count < n else -1)