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

n = int(input())
numbers = list(map(int, input().split()))

if numbers == [] or 1 not in numbers:
    print(-1)
    sys.exit(0)

index = 0
value = 1
breaks = 0
while True:
    while numbers[index] != value:
        if index >= len(numbers):
            print(-1)
            sys.exit(0)
        numbers.pop(index)
        breaks += 1
    index += 1
    value += 1
    if index >= len(numbers):
        print(breaks)
        sys.exit(0)

Fixed submission:
import sys

n = int(input())
numbers = list(map(int, sys.stdin.readline().split()))

if 1 not in numbers:
    print(-1)
    sys.exit(0)

breaks = 0
current = 1
for i in range(n):
    if numbers[i] == current:
        current += 1
    else:
        breaks += 1
print(breaks)

Buggy python submission (verdict: Runtime Error):
import sys

n = int(input())
numbers = list(map(int, input().split()))

if numbers == []:
    print(-1)
    sys.exit(0)

index = 0
value = 1
breaks = 0
while True:
    while numbers[index] != value:
        if index >= len(numbers):
            print(-1)
            sys.exit(0)
        numbers.pop(index)
        breaks += 1
    index += 1
    value += 1
    if index >= len(numbers):
        print(breaks)
        sys.exit(0)

Fixed submission:
import sys

n = int(input())
numbers = list(map(int, sys.stdin.readline().split()))

if 1 not in numbers:
    print(-1)
    sys.exit(0)

breaks = 0
current = 1
for i in range(n):
    if numbers[i] == current:
        current += 1
    else:
        breaks += 1
print(breaks)

Buggy python submission (verdict: Runtime Error):
n = int(input())
numbers = list(map(int, input().split()))


def destroy(ns):
    if len(ns) == 0:
        return None
    if len(ns) == 1:
        return 0 if ns[0] == 1 else None
    satisfies = True
    for i, s in enumerate(ns):
        if i + 1 != s:
            satisfies = False
            break
    if satisfies:
        return 0
    min_breaks = None
    if ns[0] != 1:
        ans = destroy(ns[1:])
        if ans is None:
            return None
        return 1 + ans
    for i in range(len(ns) - 1):
        breaks = destroy(ns[:i] + ns[i+1:])
        if breaks is None:
            continue
        breaks += 1
        if min_breaks is None:
            min_breaks = breaks
            continue
        if breaks < min_breaks:
            min_breaks = breaks
    return min_breaks

ans = destroy(numbers)
print(-1 if ans is None else ans)

Fixed submission:
import sys

n = int(input())
numbers = list(map(int, sys.stdin.readline().split()))

if 1 not in numbers:
    print(-1)
    sys.exit(0)

breaks = 0
current = 1
for i in range(n):
    if numbers[i] == current:
        current += 1
    else:
        breaks += 1
print(breaks)

Buggy python submission (verdict: Runtime Error):
n = int(input())
numbers = list(map(int, input().split()))


def destroy(ns):
    if len(ns) == 0:
        return None
    satisfies = True
    for i, s in enumerate(ns):
        if i + 1 != s:
            satisfies = False
            break
    if satisfies:
        return 0
    min_breaks = None
    if ns[0] != 1:
        ans = destroy(ns[1:])
        if ans is None:
            return None
        return 1 + ans
    for i in range(len(ns) - 1):
        breaks = destroy(ns[:i] + ns[i+1:])
        if breaks is None:
            continue
        breaks += 1
        if min_breaks is None:
            min_breaks = breaks
            continue
        if breaks < min_breaks:
            min_breaks = breaks
    return min_breaks

ans = destroy(numbers)
print(-1 if ans is None else ans)

Fixed submission:
import sys

n = int(input())
numbers = list(map(int, sys.stdin.readline().split()))

if 1 not in numbers:
    print(-1)
    sys.exit(0)

breaks = 0
current = 1
for i in range(n):
    if numbers[i] == current:
        current += 1
    else:
        breaks += 1
print(breaks)