Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

if not 0 in A:
    print(-1)
else:
    nf = 0
    for j in range(N+1):
        # jは残す数
        try:
            nf = A[nf:].index(j)
        except ValueError:
            break

    print(N - j)

Fixed submission:
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

rem = 0
bk = 0
for a in A:
    if a == rem:
        rem += 1
    else:
        bk += 1

if bk == N:
    print(-1)
else:
    print(bk)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

if not 0 in A:
    print(-1)
else:
    for j in range(N+1):
        # jは残す数
        try:
            nf = A.index(j)
            A = A[nf:]
        except ValueError:
            break

    print(N - j)

Fixed submission:
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

rem = 0
bk = 0
for a in A:
    if a == rem:
        rem += 1
    else:
        bk += 1

if bk == N:
    print(-1)
else:
    print(bk)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

if not 0 in A:
    print(-1)
else:
    for j in range(N+1):
        # jは残す数
        if j in A:
            nf = A.index(j)
            A = A[nf:]
        else:
            break

    print(N - j)

Fixed submission:
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

rem = 0
bk = 0
for a in A:
    if a == rem:
        rem += 1
    else:
        bk += 1

if bk == N:
    print(-1)
else:
    print(bk)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

minlen = 10**9
for k in range(N, 0, -1):
    # kは残す数
    A_ = A[:]
    for j in range(k):
        if j in A_:
            nf = A_.index(j)
            A_ = A_[nf:]
        else:
            break
    else:
        minlen = min(minlen, N - k)
        break

if minlen >= N:
    print(-1)
else:
    print(minlen)


Fixed submission:
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

rem = 0
bk = 0
for a in A:
    if a == rem:
        rem += 1
    else:
        bk += 1

if bk == N:
    print(-1)
else:
    print(bk)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

minlen = 10**9
for k in range(1, N+1):
    # kは残す数
    A_ = A[:]
    for j in range(k):
        if j in A_:
            nf = A_.index(j)
            A_ = A_[nf:]
        else:
            break
    else:
        minlen = min(minlen, N - k)

if minlen >= N:
    print(-1)
else:
    print(minlen)

Fixed submission:
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

rem = 0
bk = 0
for a in A:
    if a == rem:
        rem += 1
    else:
        bk += 1

if bk == N:
    print(-1)
else:
    print(bk)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

minlen = 10**9
for k in range(1, N+1):
    # kは残す数
    A_ = A[:]
    for j in range(k):
        if j in A_:
            nf = A_.index(j)
            A_ = A_[nf:]
        else:
            break
    else:
        minlen = min(minlen, N - k)

if minlen >= N:
    print(-1)
else:
    print(minlen)


Fixed submission:
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

rem = 0
bk = 0
for a in A:
    if a == rem:
        rem += 1
    else:
        bk += 1

if bk == N:
    print(-1)
else:
    print(bk)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

minlen = 10**9
for i in range(1, 2**N):
    remain = 0
    for j in range(N):
        if (i >> j) & 1:
            # 残す
            if A[j] == remain:
                remain += 1
            else:
                break
    else:
        minlen = min(minlen, (N - remain))

if minlen >= N:
    print(-1)
else:
    print(minlen)

Fixed submission:
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

rem = 0
bk = 0
for a in A:
    if a == rem:
        rem += 1
    else:
        bk += 1

if bk == N:
    print(-1)
else:
    print(bk)