Problem:


Score : 400 points

Problem Statement

We have N bricks arranged in a row from left to right.

The i-th brick from the left (1 \leq i \leq N) has an integer a_i written on it.

Among them, you can break at most N-1 bricks of your choice.

Let us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \leq i \leq K), the i-th of those brick from the left has the integer i written on it.

Find the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.

Constraints

All values in input are integers.

1 \leq N \leq 200000

1 \leq a_i \leq N

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.

Sample Input 1

3
2 1 2

Sample Output 1

1

If we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.

Sample Input 2

3
2 2 2

Sample Output 2

-1

In this case, there is no way to break some of the bricks to satisfy Snuke's desire.

Sample Input 3

10
3 1 4 1 5 9 2 6 5 3

Sample Output 3

7

Sample Input 4

1
1

Sample Output 4

0

There may be no need to break the bricks at all.



Sample input:
3
2 1 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    n = sc.intarr()[0]
    A = sc.intarr()
    origin_len = len(A)

    count = 1
    for i in range(0, n):
        try:
            index = A.index(count)
            A = A[index:]
            count += 1
        except ValueError:
            if count == 1:
                print("-1")
                return
            else:
                print(origin_len + 1 - count)
                return
            break
    print(origin_len - len(A))


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(x, y):
    return (x * y) // gcd(x, y)


def natural_num(n):
    for j in range(2, int(math.sqrt(n))+1):
        if n % j == 0:
            return 0
    return 1


main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))

if 1 not in A:
    print(-1)

for i in range (1, 200000):
    if i not in A:
        break
    t=A.index(i)
    A=A[t+1::]

print(N-i+1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)

def main():
    N = int(input())
    a_l = " ".join([str(i) for i in input().split()])
    pos = a_l.find("1")
    if pos == -1:
        print(-1)
        sys.exit()
    counter = 1
    for i in range(2, N + 1):
        pos = a_l[pos:].find(str(i))
        if pos != -1:
            counter += 1
        else:
            break
    print(N - counter)
    sys.exit()


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
i = 1
n = 0
if 1 not in a:
    i = -1
else:
    while True:
        n += a.index(i)
        a = a[a.index(i):-1]
        if i+1 not in a:
            n += len(a)-1
            break
        i += 1

print(n)

Submission status: Wrong Answer

Solution code:
Num = int(input())

Str = input().split(" ")

NumList = [int(s) for s in Str]

Count = 0
Break = 1
for i in range(len(NumList)):
  if Break == NumList[i]:
    Break += 1
  else:
    Count += 1
    
print(Count)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
if 1 not in a:
    print(-1)
else:
    p = 0
    ans = 0
    for i in range(1, N+1):
        for j in range(p, N):
            if i != a[j]:
                ans += 1
            else:
                p = j + 1
                break
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

if (list(range(1, N + 1)) == A):
    print(0)
else:
    N = N + 1
    A.append(-1)
    for i in range(1, N + 1):
        try:
            ind = A.index(i)
            A = A[ind + 1:]
        except:
            break

    if (i == 1):
        print(-1)
    else:
        print(N - ind - 2)

Submission status: Wrong Answer

Solution code:
N = int(input())
aa = list(map(int, input().split()))

if 1 not in aa:
    print(-1)
    exit()
count = 0
for i in range(max(aa)):
    if i+1 not in aa:
        break
    while aa[i] != i+1:
        if i+1 not in aa:
            break
        del aa[i]
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left
from collections import deque
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().strip().split()]
B = set(A)
ans = deque([])

for n in range(1, N+1):
    if n not in A:
        break
    f = A.index(n)
    ans.append(f)
    A = A[f+1:]
    if f == len(A):
        break

if len(ans) == 0:
    print(-1)
else:
    print(sum(ans))

Submission status: Wrong Answer

Solution code:
a = int(input())
l=list(map(int ,input().split()))
p=0
u=1
for i in range(a):
    if l[i]==u:
        u+=1
    else:
        p+=1    
print(p)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

#単入力
n=int(input())

#リスト入力
l = [int(i) for i in input().split()]

count = 0
for i in range(1,200000):
    try:
        position=l.index(i)
    except ValueError:
        break
    del l[:position]
if count == 0:
    print(-1)
else:
    print(n-count)

Submission status: Wrong Answer

Solution code:
n = int(input())
mx = 200000
mem = set()
a = list(map(int,input().split()))
num = [0 for _ in range(mx+1)]
for v in a:
    num[v]+=1
start = 1
for i in range(n):
    if num[start]>0:
        start+=1
        num[a[i]]-=1
ans =(n-(start-1))
if ans <= n-1:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def solve():
    N, *a = map(int, open(0).read().split())
    
    if 1 not in a:
        print(-1)
        exit()
    
    ans = 0
    for index, x in enumerate(a):
        if x == 1:
            ans = index
            break
    
    num, i = 2, ans
    cur, flag = 0, False
    while i < N:
        flag = False
        for index, m in enumerate(a[i:]):
            if m == num:
                cur = index + i
                flag = True
        if not flag:
            break
        ans += cur - i - 1
        i = cur
        num += 1
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
now = 1
cnt = 0
flag = 2
if n == 1 and A[0] == 1:
    flag = 0
elif n == 1 and A[0] != 1:
    flag = 1
elif len(set(A)) == 1 and A[0] == 1:
    cnt = n -1
elif  len(set(A)) == 1 and A[0] != 1:
    flag = 1
else:
    for a in A:
        if a == now:
            now += 1
        else:
            cnt += 1

if flag == 0:
    print(0)
elif flag == 1:
    print(-1)
else:
    print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

s = 1
count = 0
ans = 0
for a in A:
    if a == s:
        s += 1
        ans += count
        count = 0
    else:
        count += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left
from collections import deque
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().strip().split()]
B = set(A)
ans = deque([])
if 1 not in B:
    print(-1)
    exit()

for n in range(1, N+1):
    if n not in A:
        break
    f = A.index(n)
    ans.append(f)
    A = A[f+1:]
    if f == len(A):
        break

print(ans)
if len(ans) == 0:
    print(-1)
else:
    print(sum(ans))

Submission status: Wrong Answer

Solution code:
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) or value not in numbers:
            print(-1)
            sys.exit(0)
        numbers.pop(index)
        breaks += 1
    index += 1
    value += 1
    if index >= len(numbers):
        print(breaks)
        sys.exit(0)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
a=list(map(int,input().split()))
idx=0
if 1 not in a:
  print('-1')
  sys.exit()
for i in range(1,n+1):
  for j in range(idx,n):
    if a[j]==i:
      idx=j
      break
  if idx==n-1:
    print(n-i)
    sys.exit()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
def isPossible(n):
    cnt = 1
    for a in A:
        cnt += (cnt == a)
    return n < cnt

if (1 not in A):
    print(-1)
else:
    lb = 1
    ub = 200000
    for i in range(25):
        if (ub-lb == 1): break
        mid = (lb + ub) // 2
        if isPossible(mid):
            lb = mid
        else:
            ub = mid
    print(N-lb)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
x = 1
ans = 0
crash = 0

for i in range(N):
    if (a[i] == x):
        ans += crash
        crash = 0
        x += 1
        continue
    crash += 1

if (ans == 0 and crash != 0):
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = [0] + list(map(int,input().split()))
    for i in range(1,n):
        if i-1 == a[i]:
            print(n-i)
            return
    else:
        print(-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
lis = list(map(int,input().split()))
current = 0
ans = 0
positions = [-1]
for i in range(N):
  if lis[i] - current == 1:
    positions.append(i)
    current = lis[i]
if len(positions) == 1:
  print(-1)
else:
  for j in range(len(positions)-1):
    ans += positions[j+1] - positions[j] - 1
  print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))

ans = 1
count = 1
y = 0

if A.count(1) == 0:
    ans = -1
else:
    for i in range(n):
        try:
            x = A[y:].index(count) + len(A[:y])
            ans += x - y -1
            y = x
            count += 1
        except:
            break

print (ans)

Submission status: Wrong Answer

Solution code:
import sys

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

ans = 0

if not 1 in set(a):
    print(-1)
    sys.exit()

for i in range(1,n):
    _find = False
    _break = 0
    for g in range(len(a)):
        if i==a[g]:
            _break = g
            _find = True
            break
    if _find is False:
        break
    ans+=_break
    a=a[_break+1:]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input()) 
a = [int(i) for i in input().split()]

if 1 not in a:
    print(-1)

num = 1
ans = 0
for i in a:
    if i == num:
        num += 1
    else:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

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

index = 0
value = 1
breaks = 0
try:
    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)
except:
    print(breaks)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
import datetime
import itertools
import sys
import copy

# 入力
#N = int(input())
#S = str(input())
#N, A, B = map(int, input().split())
N = int(input())
L = list(map(int, input().split()))

if N == 1 and L[0] == 1 :
  print (1)
  exit()

index = 1
cnt = 0
for i in range(N) :
  if L[i] == index :
    index += 1
    cnt += 1

if cnt == 0 :
  print (-1)
else :
  print (N-cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
aa = list(map(int, input().split()))

if 1 not in aa:
    print(-1)
    exit()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]

save = 1
ans = -1

for i in a:
    if save == i:
        if i == 1:
            ans += 1
        save += 1
    else:
        ans += 1
print(ans if len(a) != ans else '-1')

Submission status: Wrong Answer

Solution code:
n = int(input())
mem = set()
a = list(map(int,input().split()))
num = [0 for _ in range(n+1)]
for v in a:
    num[v]+=1
start = 1
for i in range(n):
    if num[start]>0:
        start+=1
        num[a[i]]-=1
ans =(n-(start-1))
if ans != n:
    print(ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys

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

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

index = 0
value = 1
breaks = 0
try:
    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)
except:
    print(-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))

ans = 0
cnt = 0
num = 1
for i in range(N):
    if a[i] != num:
        cnt += 1

    else:
        ans += cnt
        cnt = 0
        num += 1
if 1 not in a:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

if(list(range(1,N+1))==A):
  	print(0)
else:
    for i in range(1, N+1):
        try:
            ind = A.index(i)
            A = A[ind:]
        except:
            break
    if(i==1):
        print(-1)
    else:
        print(N-ind)

Submission status: Wrong Answer

Solution code:
n = int(input())
an = list(map(int, input().split()))

count = 0

if len(an) == 1:
  print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
count=1
sum1=0
for i in range(n):
    if a[i]==count:
        count+=1
    else:
        sum1+=1
if n==sum:
    print("-1")
else:
    print(sum1)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
tmp=1
ans=0
for i in l:
    if i==tmp:
        tmp+=1
    else:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
s=1
i=0
while i<N:
  if s==A[i]:
    s+=1
  i+=1
mi=N-s
if 1 not in A:
  print(-1)
else:
  print(mi)

Submission status: Wrong Answer

Solution code:

def main():
    N = int(input())
    A = [int(i) for i in input().split(" ")]

    size = len(A)
    i=1
    count = 0
    while size >1:
        try:
            ind = A.index(i)
        except ValueError:
            print(-1)
            return 0;
        count += ind
        A=A[ind+1:]
        i = i+1
        size = len(A)
    print(count)


if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
# import numpy as np
import sys
input = sys.stdin.readline

N = int(input())
a = list(map(int,input().split()))

k = 1

seta = set(a)

res = -1

while k in seta:
    index = a.index(k)
    if res == -1:
        res = index
    else:
        res += index
    k += 1
    a = a[index+1:]
    seta = set(a)

print(res)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split(" ")))

count=0
target=1
suc=0
for i in range(N):
    if a[i]!=target:
        count+=1
    else:
        suc+=1

if suc>0:
    print(count)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))


    if len(A) == 1 and A[0] == 1:
        print(0)
        exit()

    set_A = set(A)
    t = 1
    for i in range(1, len(A)):
        if not i in set_A:
            break
        t += 1
    if t == 1:
        print(-1)
        exit()

    ans = 0
    tt = 1
    for a in A:
        if tt == t:
            ans += 1
            continue
        if a == tt:
            tt += 1
            ans += 1
        else:
            pass

    print(len(A)-ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
s=1
i=0
while i<N:
  if s==A[i]:
    s+=1
  i+=1
mi=N-s
if mi==N:
  print(-1)
else:
  print(mi)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
now = 1
cnt = 0
flag = 2
if len(set(A)) == 1 and A[0] == 1:
    flag = 0
elif len(set(A)) == 1 and A[0] != 1:
    flag = 1
else:
    for a in A:
        if a == now:
            now += 1
        else:
            cnt += 1

if flag == 0:
    print(0)
elif flag == 1:
    print(-1)
else:
    print(cnt)

Submission status: Wrong Answer

Solution code:
from sys import stdin 
n = int(stdin.readline().rstrip())
s = [int(x) for x in stdin.readline().rstrip().split()]
t = 1
answer = 0
for i in range(n):
    if s[i] == t:
        t += 1
    else:
        answer += 1
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())

a = list(map(int,input().split()))
flag = 0
count = 0

if 1 in a:
    flag = 1

for i in range(1,n+1):
    if i in a:
        indx = a.index(i)
        count += indx
        a = a[indx+1:]

if flag!=0:
    print(count)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left
from collections import deque
input = sys.stdin.readline
N = int(input())
A = [0] + [int(x) for x in input().strip().split()]
B = set(A)
ans = deque([])
if 1 not in B:
    print(-1)
    exit()

for n in range(N+1):
    f = bisect_left(A, n)
    ans.append(f)
    A = A[f+1:]
    if f > N:
        break

print(sum(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(n) for n in input().split()]

ret = -1
for i in range(N):
    copyA = A.copy()
    for j in range(i):
        copyA.pop(0)

    for p, a in enumerate(copyA):
        if (p+1) == a:
            ret = i
            break

print(ret)

Submission status: Wrong Answer

Solution code:
n=int(input())
li=list(map(int,input().split()))	
cnt=0
num=1
p=0
for i in range(n):
  if li[i] == num:
    cnt += i-p
    p=i+1
    num += 1
if num==1:
  cnt=-1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
result = 0
num = 1
if A.count(1) == 1 and len(A) == 1:
    print(0)
elif A.count(1) > 0:
    for i in range(N):
        if A[i] != num:
            result += 1
        else:
            num += 1
    print(-1 if result == 0 else result)

else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int, input().split()))
count = 0
tmp=0
for i in range(N):
    if A[i]!=tmp+1:
        count +=1
    else:
        tmp+=1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
la = list(map(int, input().split()))

bb = 0
left = 0

for i in range(n):
    for j in range(left, n):
        if la[j] == i+1:
            left = j + 1
            break
        else:
            bb += 1

if bb >= n:
    print(-1)
else:
    print(bb)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a= np.array(list(map(int,input().split())))
num = [i+1 for i in range(n)]
num = np.array(num)

num2=num - a
min=10000000
for i in range(n):
  if (num2[i]<min) and (num2[i]>-1):
    min = num2[i]
    min_n = i

print(min_n)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
tmp = 1

for i in range(n):
  if a[i] == tmp:
    tmp += 1
  else:
    ans += 1

if ans == 0 and tmp != 0:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
add,point,cnt=0,1,0
num=set(A)
while add!=n:
    if A[add]==point:
        point +=1
    else:
        cnt +=1
    add +=1
print(cnt if cnt!=0 or point-1==n else -1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = [0]+list(map(int, input().split( )))
tmp = 0
cnt =0
if 1 not in a:
    print(-1)
    exit()
for i in range(n+1):
    while tmp < n and a[tmp]!=i:
        tmp += 1
        cnt += 1
        #print(i,tmp,cnt)
    tmp += 1
    if tmp >= n:
        break


print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()][::-1]
cnt = 0
num = A[0]
if 1 not in A:
  print(-1)
  exit()
for i in range(N-1):
  if num <= A[i+1]:
    cnt += 1
  else:
    num = A[i+1]
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
tmp = 1

for i in range(n):
  if a[i] == tmp:
    tmp += 1
  else:
    ans += 1

if ans == 0:
  print(-1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
n  = int(input())
xs = [int(x) for x in input().split()]
x  = -1

for i in range(1, n + 1):
	if i <= xs[i - 1]:
		x = i - xs[i - 1]

print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]

ans = 0

tmp = 1
for n in range(N):
    if A[n] == tmp:
        ans += 1
        tmp += 1
print(N - ans)

Submission status: Wrong Answer

Solution code:
1
1

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

want=1
ans=0
for i in range(N):
    if A[i]==want:
        want+=1
    else:
        ans+=1

if A[i]!=1:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = 0
tmp = 1

for i in range(n):
  if a[i] == tmp:
    tmp += 1
  else:
    ans += 1
    

print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def main():
    # input = sys.stdin.readline
    N = int(input())
    raw_list = list(map(int, input().split()))
    new_list = raw_list.copy()

    count = 0
    for i in range(1, N+1):
        if i in new_list:
            idx = new_list.index(i)
            new_list = new_list[idx+1:].copy()
            count += idx

    if 1 not in raw_list:
        count = -1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
ls_a = list(map(int,input().split()))
cnt = 1
ans = 0
for i in ls_a:
    if i == cnt:
        cnt+=1
    else:
        ans += 1
# print(cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
k=1
cnt=0
for i in range(n):
  if a[i]==k:
    k+=1
    cnt+=1
print(n-cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
p=n
f=1
for i in range(n):
    if l[i]==f:
        p-=1
        f+=1
print(p if p>0 else -1)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int, input().split()))
 
cnt=0
j=1
for i in range(N):
  if j!=a[i]:
    cnt+=1
  else:
    j+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
i = 0
j = 1
ANS = []
while i < N:
    x = a[i]
    if x == j:
        ANS.append(x)
        j += 1
    i += 1
ans = N - len(ANS)
if ans == 0:
    ans = -1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
p=n
f=1
for i in range(n):
    if l[i]==f:
        p-=1
        f+=1
print(p)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = map(int, input().split())
c = 0
start = 1
for a in A:
  if a == start:
    c+=1
    start += 1
if c == N:
  print(-1)
else:
  print(N-c)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int, input().split()))

cnt=0
j=1
for i in range(N):
  if j!=a[i]:
    cnt+=1
  else:
    j+=1
print(N-cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
p=n
f=1
for i in range(n):
    if i==f:
        p-=1
        f+=1
print(p)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
ans = 0
num = 1
old_i = 0
for i in range(n):
    if l[i] == num:
        # print(i, num, ans, (i - old_i))
        num += 1
        ans += (i - old_i)
        old_i = i + 1
if num == 1:
    print(-1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n =int(input())
a = list(map(int,input().split()))
if 1 not in a:
    print(-1)
    exit(0)
num = 1
for i in range(n):
    if a[i] == num:
        if i == n-1:
            break
        else:
            
            num+=1
print(n-num)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
alst = [int(i) for i in readline().split()]

if 1 not in alst:
  print(-1)
  quit()
r = 0
c = 1
while True:
  if c not in alst:
    print(r)
    quit()
  p = alst.index(c)
  c += 1
  r += p
  alst = alst[p + 1:]

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
add,point,cnt=0,1,0
while add!=n:
    if A[add]==point:
        point +=1
    else:cnt +=1
    add +=1
print(cnt if cnt!=0 or point!=1 else -1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(item) for item in input().split()]

ans = 0
cur = 1
last = 0

if 1 not in a:
    print(-1)
else:
    for i in range(n):
        if a[i] == cur:
            ans += last
            last = 0
            cur += 1
        else:
            last += 1

    print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline-------------------------------------------- 
    n = int(input())
    a = list(map(int,input().split()))
    keep = 1
    cnt = 0
    for i in range(n):
        if a[i] == keep:
            cnt += 1
            keep += 1
    print(n - cnt)
            



if __name__ == "__main__":
    main() #endline===============================================

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

counter = 1

ans = 0

for a in A:
    if a == counter:
        counter += 1
    else:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
num=1
ans=0
for i in range(N):
    if a[i]==num:
        num+=1
    else:
        ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from fractions import *

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()
now = 1
ct = 0
for i in range(n):
    if a[i] == now:
        now += 1
        ct += 1
print(0) if ct == 0 else print(n-ct)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
c=1
for a in A:
    if a==c:
        c+=1
print(n-c+1)

Submission status: Wrong Answer

Solution code:
def main():

    N = int(input())
    a = list(map(int, input().split()))

    ans = 0
    p = 1
    for i in range(N):
        if a[i] != p:
            ans += 1
        else:
            p += 1
    return ans


if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:
N=int(input())
A = [int(i) for i in input().split()]
cur = 1
broken = 0
for a in A:
    if a!=cur:
        broken += 1
    else:
        cur += 1
print(broken)