Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
count = 0
if 1 not in a:
    print(-1)
else:
    count += a.index(1)
    prev_index = a.index(1)
    for i in range(2,N+2):
        if i not in a[prev_index:N]:
            count += N - (prev_index + 1)
            print(count)
            break
        else:
            two_ago_index = prev_index
            prev_index = a.index(i,two_ago_index)
            count += prev_index - two_ago_index -1

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
count = 1
brick = 0
for i in range(N):
    if a[i] != count:
        brick += 1
    else:
        count += 1
if brick == N:
    print(-1)
else:
    print(brick)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
count = 0
if 1 not in a:
    print(-1)
else:
    count += a.index(1)
    prev_index = a.index(1)
    for i in range(2,N+2):
        if i not in a[prev_index:N]:
            count += N - (prev_index + 1)
            print(count)
            break
        else:
            two_ago_index = prev_index
            prev_index = a.index(i,two_ago_index)
            count += prev_index - two_ago_index -1

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
count = 1
brick = 0
for i in range(N):
    if a[i] != count:
        brick += 1
    else:
        count += 1
if brick == N:
    print(-1)
else:
    print(brick)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
count = 0
if 1 not in a:
    print(-1)
else:
    count += a.index(1)
    prev_index = a.index(1)
    for i in range(2,N+2):
        if i not in a[prev_index:N]:
            count += N - (prev_index + 1)
            print(count)
            break
        else:
            count += a.index(i,prev_index) - prev_index -1
            two_ago_index = prev_index
            prev_index = a.index(i,prev_index)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
count = 1
brick = 0
for i in range(N):
    if a[i] != count:
        brick += 1
    else:
        count += 1
if brick == N:
    print(-1)
else:
    print(brick)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
count = 0
if 1 not in a:
    print(-1)
else:
    count += a.index(1)
    prev_index = a.index(1)
    for i in range(2,N+2):
        if i not in a[prev_index:N]:
            count += N - (prev_index + 1)
            print(count)
            break
        else:
            count += a.index(i,prev_index) - prev_index -1
            two_ago_index = prev_index
            prev_index = a.index(i,prev_index)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
count = 1
brick = 0
for i in range(N):
    if a[i] != count:
        brick += 1
    else:
        count += 1
if brick == N:
    print(-1)
else:
    print(brick)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
count = 0
if 1 not in a:
    print(-1)
else:
    count += a.index(1)
    prev_index = a.index(1)
    for i in range(prev_index):
        a[i] = 0
    for i in range(2,N+2):
        if i not in a:
            count += N - (prev_index + 1)
            print(count)
            break
        else:
            count += a.index(i) - prev_index -1
            two_ago_index = prev_index
            prev_index = a.index(i)
            for j in range(two_ago_index,prev_index+1):
                a[j] = 0

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
count = 1
brick = 0
for i in range(N):
    if a[i] != count:
        brick += 1
    else:
        count += 1
if brick == N:
    print(-1)
else:
    print(brick)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
count = 0
if 1 not in a:
    print(-1)
else:
    count += a.index(1)
    prev_index = a.index(1)
    for i in range(prev_index):
        a[i] = 0
for i in range(2,N+2):
    if i not in a:
        count += N - (prev_index + 1)
        print(count)
        break
    else:
        count += a.index(i) - prev_index -1
        two_ago_index = prev_index
        prev_index = a.index(i)
        for j in range(two_ago_index,prev_index+1):
            a[j] = 0

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
count = 1
brick = 0
for i in range(N):
    if a[i] != count:
        brick += 1
    else:
        count += 1
if brick == N:
    print(-1)
else:
    print(brick)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
count = 0
if 1 not in a:
    print(-1)
else:
    count += a.index(1)
    prev_index = a.index(1)
    for i in range(prev_index):
        a[i] = 0
for i in range(2,N+2):
    if i not in a:
        count += N - (prev_index + 1)
        break
        print(count)
    else:
        count += a.index(i) - prev_index -1
        two_ago_index = prev_index
        prev_index = a.index(i)
        for j in range(two_ago_index,prev_index+1):
            a[j] = 0

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
count = 1
brick = 0
for i in range(N):
    if a[i] != count:
        brick += 1
    else:
        count += 1
if brick == N:
    print(-1)
else:
    print(brick)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
count = 0
if 1 not in a:
    print(-1)
else:
    count += a.index(1)
    prev_index = a.index(1)
    for i in range(prev_index):
        a[i] = 0
for i in range(2,N+2):
    if i not in a:
        count += N - (prev_index + 1)
        break
    else:
        count += a.index(i) - prev_index -1
        two_ago_index = prev_index
        prev_index = a.index(i)
        for j in range(two_ago_index,prev_index+1):
            a[j] = 0
print(count)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
count = 1
brick = 0
for i in range(N):
    if a[i] != count:
        brick += 1
    else:
        count += 1
if brick == N:
    print(-1)
else:
    print(brick)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
count = 0
if 1 not in a:
    print(-1)
else:
    count += a.index(1)
    prev_index = a.index(1)
    for i in range(prev_index):
        a[i] = 0
for i in range(2,N+2):
    if i not in a:
        count += N - prev_index - 1
        break
    else:
        count += a.index(i) - prev_index -1
        prev_index = a.index(i)
        for j in range(prev_index):
            a[j] = 0
print(count)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
count = 1
brick = 0
for i in range(N):
    if a[i] != count:
        brick += 1
    else:
        count += 1
if brick == N:
    print(-1)
else:
    print(brick)