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.

Solution (Python):
def main():
	N = int(input())
	a = list(map(int, input().split()))
	num = 1
	cnt = 0
	if 1 not in a:
		print(-1)
	else:
		for i in range(N):
			if a[i] == num:
				num += 1
			else:
				cnt += 1
		print(cnt)



if __name__ == '__main__':
	main()

Solution (Python):
N = int(input())
brick = list(map(int, input().split()))
n = 0
br = 0
flg = False
for b in brick:
    if b == n + 1:
        n += 1
        flg = True
    else:
        br += 1
if flg:
    print(br)
else:
    print(-1)

Solution (Python):
n,c=int(input()),0
for i in map(int,input().split()):
  if i==c+1: c+=1
print(n-c if c else -1)

Solution (Python):
n=int(input())
l=map(int,input().split())
c=0
for i in l:
  if i==c+1: c+=1
print(n-c if c else -1)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = 1
for i in range(n):
    if ans == a[i]:
        ans += 1
    else:
        continue

if ans == 1:
    print(-1)
else:
    print(n - ans + 1)

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
match = 1
for i in li:
    if i == match:
        match += 1
if 1 in li:
    print(n-match + 1)
else:
    print(-1)

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

Solution (Python):
n = int(input())
aa = list(map(int, input().split()))

ans = 0
x = 1
for a in aa:
    if a == x:
        x += 1
    else:
        ans += 1
if x == 1:
    print(-1)
else:
    print(ans)

Solution (Python):

def submit():
    n = int(input())
    alist = list(map(int, input().split()))

    curr = 0
    for a in alist:
        if a == curr + 1:
            curr += 1
    
    if curr == 0:
        print(-1)
    else:
        print(n - curr)


if __name__ == "__main__":
    submit()

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

index = 0
ans = 0
for i in range(N):
    if a[i] == index+1:
        index +=1
    else:
        ans +=1
if ans == N:
    print(-1)
else:
    print(ans)

Solution (Python):
import sys

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

count = 0

for i in range(N):
    if a[i] == i + 1 - count:
        pass
    else:
        count += 1
        
if count == N:
    print(-1)
else:
    print(count)

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

if not 1 in a:
    print(-1)
    quit()

i = 1
cnt = 0
for ai in a:
    if ai != i:
        cnt += 1
    elif ai == i:
        i += 1

print(cnt)

Solution (Python):

import sys


def solve(N: int, a: "List[int]"):
    if 1 not in a:
        print(-1)
        return
    ans = 0
    nxt = 1
    for i in range(N):
        if a[i] == nxt:
            nxt += 1
        else:
            ans += 1
    print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(N, a)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
num = list(map(int, input().split()))
cnt = [1]*n
flug = 1
for i in range(n):
  if num[i] == flug:
      cnt[i] = 0
      flug += 1
if sum(cnt) == n:
  print(-1)
else:
  print(sum(cnt))

Solution (Python):
n=int(input())
a=map(int,input().split())
i=1
for k in a:
  if k==i: i+=1
print(n-i+1 if i>1 else -1)

Solution (Python):
N=int(input())
A=map(int,input().split())
i=1
for a in A:
  if a==i: i+=1
i-=1
print(N-i if i>0 else -1)

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

cnt = 1
for a in A:
    if a==cnt:
        cnt+=1

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

Solution (Python):
N=int(input())
A=map(int,input().split())
i=1
for a in A:
  if a==i: i+=1
i-=1
print(N-i if i>0 else -1)

Solution (Python):

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

Solution (Python):
n = int(input())
li = [int(x) for x in input().split()]
ans = 0
x = 1
for i in range(n):
    if li[i]==x:
        x+=1
    else:
        ans+=1

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

Solution (Python):
N = int(input())
nums = list(map(int,input().split(" ")))

t = 1
s = 0
for i in range(N):
    if nums[i] == t:
        t += 1
    else:
        s += 1

if s <= N - 1:
    print(s)
else:
    print(-1)

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

Solution (Python):
N = int(input())

S = list(map(int,input().split()))
if 1 not in S:
  print(-1)
else:
  start = 1
  for i in S:
    if i == start:
      start+=1
  else:
    print(N-start+1)

Solution (Python):
import sys

n = int(sys.stdin.readline().strip())
nums = map(int, sys.stdin.readline().split())
nums = list(nums)
if 1 not in nums:
    print(-1)
    sys.exit(0)
crt = 1

for i in range(n):
    if nums[i] == crt:
        crt += 1
    
print(n - crt + 1)

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

num = 1
for i in a:
    if i == num:
        num += 1

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

Solution (Python):
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


n = int(input())
a_list = list(map(int,input().split()))
ans = len(a_list)
ini = 1
for l in a_list:
    if l == ini:
        ans -= 1
        ini += 1

if ans < len(a_list):
    print(ans)
else:
    print(-1)

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

count = 0
for a_i in a:
    if a_i == count+1:
        count += 1
        check = 1

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

Solution (Python):






import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache






MOD = 10**9 +7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


def lcm(a, b):
    return a * b // gcd (a, b)





N = inputI()
l = inputIL()

now = 0
boom = 0
for i in l:
  if i != now + 1:
    boom += 1
  else:
    now += 1
    
if boom == N:
  print("-1")
else:
  print(boom)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
now=0
for i in range(n):
    if A[i] == now+1:
        now+=1
if now==0:
  print(-1)
  exit()
print(n-now)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
num = 1
for i in a:
    if i == num:
        num += 1
    
print(len(a) - num + 1 if num != 1 else -1)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))
count=1
if 1 not in A:
  print(-1)
else:
  for i in range(N):
    if A[i]==count:
      count+=1
  print(N-(count-1))

Solution (Python):
import sys
input=sys.stdin.readline
N = int(input())
a = list(map(int,input().split()))
c = 1
n = 0
for i in range(N):
    if a[i] == c:
        c += 1
    else:
        n += 1
if c == 1:
    print(-1)
else:
    print(n)

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))

rem = []
count = 1
for i in range(len(arr)):
    if count == arr[i]:
        rem.append(arr[i])
        count += 1

if len(rem) == 0:
    print(-1)
else:
    print(len(arr) - len(rem))

Solution (Python):
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    a = list(map(int,input().split()))
    now,count = 1,0
    for num in a:
        if num == now:
            count += 1
            now += 1
    
    print(N-count if count!=0 else -1)
    
if __name__ == "__main__":
    main()

Solution (Python):
import itertools
import sys
import math
import numpy as np
import fractions
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
from bisect import insort
sys.setrecursionlimit(10**9)

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

    ch_max = 0
    for a in A:
        if ch_max + 1 == a:
            ch_max += 1

    if ch_max == 0:
        print(-1)
        exit()

    print(N - ch_max)




if __name__ == "__main__":
  main()

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
k=0
for i in range(N):
  if A[i]==k+1:
    k+=1
if k==0:
  k=N+1
print(N-k)

Solution (Python):
import sys
input = sys.stdin.readline
import fractions 
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  count = 1
  ans = 0
  for i in range(n):
    if a[i] != count:
      ans += 1

    else:
      count += 1
  if count == 1:
    print(-1)
  else:
    print(ans)
  
  
solve()

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

point = 1
nums = []
for i in range(len(a)):
    if a[i] == point:
        point += 1
        nums.append(a[i])

if not nums:
    print('-1')
else:
    print(len(a) - len(nums))

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))
ans = 0
wait_for = 1
for a in a_list:
    if a == wait_for:
        wait_for += 1
    else:
        ans += 1
if wait_for == 1:
    print(-1)
else:
    print(ans)

Solution (Python):
num = int(input())
num_list = [int(a) for a in input().split()]
target = 1
ans = 0
flg = False

for i in range(num):
    if num_list[i] == target:
        target += 1
        flg = True
    else:
        ans += 1

if not flg:
    ans = -1

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
cnt = 0
num = 1
for a in A:
    if a==num:
        num += 1
    else:
        cnt += 1
if cnt==N:
    print(-1)
else:
    print(cnt)

Solution (Python):











n = int(input())





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

c = 0
idx = 1
for i in range(n):
    if a[i] == idx:
        c += 1
        idx += 1

print(n-c if c > 0 else -1)

Solution (Python):

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

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

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


l = []
ans = 0

cnt = 1

flg = True

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


if flg:
    print(-1)
else:
    print(ans)

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
cnt = 0
for a in A:
    if a == cnt + 1:
        cnt += 1
if cnt:
    print(N - cnt)
else:
    print(-1)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
ans = 0
t = 1
for i in a:
    if i == t:
        t += 1
    else:
        ans += 1
if ans == len(a):
    print(-1)
else:
    print(ans)

Solution (Python):
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007
"""

    n,k,m=LI() 
    
    
    
    
    N=I()
    p=LIR(N)
    print(n,k,m,p)
"""
def resolve():
    n=I()
    a=LI()

    numc=1
    breakc=0
    
    for i in range(n):
        if a[i]==numc:
            numc+=1
        else:
            breakc+=1
    if numc==1:
        print(-1)
    else:
        print(breakc)

    return

import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3
2 1 2"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3
2 2 2"""
        output = """-1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """10
3 1 4 1 5 9 2 6 5 3"""
        output = """7"""
        self.assertIO(input, output)
    def test_入力例_4(self):
        input = """1
1"""
        output = """0"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

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

cnt = 1
delete = 0

for i in a:
    if i == cnt:
        cnt += 1
    else:
        delete += 1
if delete == N:
    print(-1)
else:
    print(delete)

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

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

if a.count(1) == 0:
    print(-1)
else:
    ans = 0
    for i in range(len(a)):
        if a[i] != count:
            ans += 1
        else:
            count += 1
    print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

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

c = 0
for i, x in enumerate(a):
    if x == c + 1:
        c += 1

ans = N - c
print(ans) if ans != N else print(-1)

Solution (Python):
N=int(input())
alist=list(map(int,input().split()))

num_seq=0
for a in alist:
  if a==num_seq+1:
    num_seq+=1
    
if num_seq==0:
  print(-1)
else:
  print(N-num_seq)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
count = 0
for i in range(n):
    if a[i] == count + 1:
        count += 1
if count:
    print(n - count)
else:
    print(-1)

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

cnt=0
for i in a:
  if i == (cnt+1):
    cnt += 1
if cnt == 0:
  print(-1)
else:
  print(n-cnt)

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

r = 0
index = 0
ans = 0
for i in range(n) :
  r += 1
  for j in range(n) :
    if index >= n :
      break
    if a[index] == r :
      index += 1
      break
    ans += 1
    index += 1
      
if ans == n :
  print(-1)
else :
  print(ans)

Solution (Python):
N = int(input())
brick = list(map(int,input().split()))

def Break(n, lst):
  counter = 0
  cur = 1
  for i in range(len(lst)):
    if lst[i] == cur:
      cur += 1
    else:
      counter += 1
  if cur == 1:
    return -1
  return counter

print(Break(N, brick))

Solution (Python):
N = int(input())
arr = list(map(int, input().split()))
ans = 0
target = 1
for x in arr:
    if x == target:
        target += 1
    else:
        ans += 1

if ans == N:
    ans = -1

print(ans)

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

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

s = 1
for i in range(n):
     if a[i] == s:
          s +=1
if s == 1:
     print(-1)
else:
     print(n-s+1)

Solution (Python):
import math
import itertools

N = int(input())
A = list(map(int, input().split()))
mark = 0
for a in A:
  if a == mark+1:
    mark += 1
if mark == 0:
  print(-1)
else:
  print(N-mark)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
i=1
cnt=0
for x in a:
    if x==i:i+=1
    else:cnt+=1
if cnt==n:print(-1)
else:print(cnt)

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

ans = 0
now = 0

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

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

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

if 1 not in a:
    print(-1)
else:
    find = 1
    for i in range(N):
        if a[i] == find:
            find += 1
    print(N-find+1)

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]

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

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

print(ans)

Solution (Python):
N = int(input())
a = list(map(int,input().split()))
length = 0
num = 1
l_max = 0
for i in range(N):
    if(a[i]==num):
        num+=1
        length+=1
if(length == 0):
    print("-1")
else:
    print(N-length)

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

number = 1
count = 0
for num in a:
    if num==number:
        number += 1
    else:
        count += 1

if count==n:
    print(-1)
else:
    print(count)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
cur = 1
ans = 0
if 1 not in A:
    print(-1)
    exit()
for a in A:
    if a == cur:
        cur += 1
    else:
        ans += 1
print(ans)

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

next = 1
nok = 0
for i in range(n):
   if a[i] == next:
      nok += 1
      next += 1

if nok > 0:
   print(n - nok)
else:
   print(-1)

Solution (Python):
def brick_break(n, a_list):
    c = 1
    for a in a_list:
        if a==c:
            c += 1
    if c == 1:
        return -1
    else:
        return n-c+1

n = int(input())
a_list = [int(i) for i in input().split()]

print(brick_break(n, a_list))

Solution (Python):


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

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
cnt=0
count=1
for i in range(len(a)):
    if a[i]==count:
        cnt+=1
        count+=1

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

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
cnt=1
ans=0
OK=False
for i in range(N):
    if a[i]!=cnt:
        ans+=1
    else:
        cnt+=1
        OK=True
print(ans if OK else -1)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
a = [int(x) for x in input().split()]

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

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
now = 1
for i in range(N):
    if A[i] == now:
        now += 1
print(N-now+1 if now != 1 else -1)

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

i = 1
for v in A:
    if v == i:
        i += 1
        
if i == 1:
    print(-1)
else:
    print(n - i + 1)

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

numcount = 1
for a in A:
    if a == numcount:
        numcount += 1

if numcount == 1:
    print(-1)
else:
    print(n - numcount + 1)

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

numcount = 1
for i in range(n):
    if A[i] == numcount:
        numcount += 1

if numcount == 1:
    print(-1)
else:
    print(n - numcount + 1)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
count = 1
broke = 0

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

for x in range(N):
    if a[x] == count:
        count += 1

print(N - count + 1)

Solution (Python):
from collections import deque
n = int(input())
q = deque((map(int,input().split())))
count = 1
for i in range(n):
    if count == q.popleft():
        count += 1
if count == 1:
    print(-1)
else:
    print(n-count+1)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
x=1
for i in range(n):
  if a[i]==x:
    x+=1

if x==1:
  ans=-1
else:
  ans=n-x+1

print(ans)

Solution (Python):
n = int(input())
s = list(map(int,input().split()))
flag = 1
for i in range(n):
    if s[i] == flag:
        flag += 1
if 1 not in s:
    print(-1)
else:
    print(n - flag +1)

Solution (Python):
n = int(input())
s = list(map(int,input().split()))
flag = -1
for i in range(n):
    if s[i] == 1:
        flag = 2
    if s[i] == flag:
        flag += 1
if flag == -1:
    print(-1)
else:
    print(n - flag + 1)

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

Solution (Python):
import sys
input = sys.stdin.readline

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

    i = 1
    ans = 0
    for a in A:
        if a == i:
            i += 1
        else:
            ans += 1
    if ans == N:
        print(-1)
    else:
        print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
num=list(map(int,input().split()))
count=0
check=1
for i in range(N):
    if num[i]==check:
        check+=1
    else:   
        count+=1
if check==1:
    print("-1")
else:
    print(count)

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

c=0 
n=1
for i in range(N):
    if a[i]==n:
        n+=1
    else:
        c+=1

if c==N:
    print("-1")
else:
    print(c)

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

c=0 
n=1
for i in range(N):
    if a[i]==n:
        n+=1
    else:
        c+=1

if c==N:
    print("-1")
else:
    print(c)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]

can = False
cnt = 1
for a in A:
    if a == cnt:
        can = True
        cnt += 1

if can == False:
    print(-1)
else:
    print(N-cnt+1)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=0
now=1
for i in range(n):
    if now==a[i]:
        now+=1
        pass
    else:
        ans+=1
if ans>n-1:
    print(-1)
else:
    print(ans)

Solution (Python):
n = int(input())
arrA = list(map(int,input().split()))

ans = 0
target = 1

for x in range(n):
    if arrA[x] == target:
        target += 1
        continue
    else:
        ans +=1

if ans == n:
    ans = -1

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
x = len(A)
count = 0
num = 1
for i in A:
  if i == num:
    count += 1
    num += 1
if count == 0:
  print(-1)
else:
  print(x-count)

Solution (Python):
n = int(input())

nums = list(map(int, input().split()))
l = [int(x) for x in range(1, n + 1)]

remain = [0]
count = 0

for i in nums:
    if i == remain[-1] + 1:
        remain.append(i)
    else:
        count += 1

if nums == l:
    print(0)
elif (count > 0) and (count != n):
    print(count)
else:
    print(-1)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
c=0
d=1
for i in range(n):
    if a[i]==d:
        c+=1
        d+=1
if c==0:
    print(-1)
else:
    print(n-c)

Solution (Python):
N = int(input())
a_list = [int(x) for x in input().split()]
del_list = []
cr = 1
num = 0
for i in range(N):
  if a_list[i] > i+1:
    a_list[i] = -1
for i in range(N):
  if a_list[i] == -1:
    num += 1
    continue
  if a_list[i] != cr:
    a_list[i] = -1
    continue
  cr+=1

l = [x for x in a_list if x == -1]
if len(l) == N:
  print("-1")
else:
  print(len(l))

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

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


if num == 1:
	print(-1)
else:
	print(N-num+1)

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

b = 0

for i in a:
    if i == b + 1:
        b = i
print(n - b if b != 0 else -1)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
count = 0
num = 1

for i in range(n):
    if a[i] == num:
        num += 1
        count += 1


if num == 1:
    count = -1
else:
    count = len(a) - count

print(count)

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

num = 1
for ai in a:
  if ai == num:
    num += 1

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

Solution (Python):
n=int(input())
ans=0
v=1
a=list(map(int,input().split()))
for i in a:
      if i==v:
            v+=1

if v==1:
      print(-1)
else:
      print(n-v+1)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    cnt = 1
    for i in range(N):
        if A[i] == cnt:
            cnt += 1
        else:
            ans += 1

    if A.count(1) == 0:
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

from collections import deque

N = int(input())
A = deque(map(int, input().split()))

ind = 1
cnt = 0
while A:
  x = A.popleft()
  if x != ind:
    cnt += 1
  else:
    ind += 1
print(cnt if cnt != N else -1)

Solution (Python):

n=int(input())
a=[int(x) for x in input().split()]
if not (1 in a):
    print(-1)
    exit()
start=0
sum=0
for i in range(1,n+1):
    count=0
    for j in range(start,n):
        if i == a[j]:
            count+=1
            start=j
            sum+=count
            break
    if count==0:
        break

print(n-sum)

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
ans = 0
now = 1
for i in range(N):
    if now == A[i]:
        now += 1
    else:
        ans += 1
if now == 1 and N != 1:
    print(-1)
else:
    print(ans)

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
now=0
for i in range(n):
    if A[i]==now+1:
        now+=1
print(n-now if now!=0 else -1)

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    n=int(input())
    a=list(map(int,input().split()))
    i=0
    cnt=1
    while i<=len(a)-1:
        if a[i]==cnt:
            cnt+=1
        i+=1
    if cnt==1:
        print(-1)
    else:
        print(len(a)-cnt+1)
    
if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
list_score = list(map(int, input().split()))
cnt = 1
for i in range(n):
    if list_score[i] == cnt:
        cnt += 1
ans = 0
cnt -= 1
if cnt == 0:
    ans = -1
else:
    ans = len(list_score) - cnt
print(ans)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
id=1
count=0
for i in range(N):
    if a[i]==id:
        id=id+1
    else:
        count=count+1
if count==len(a):
    print("-1")
else:
    print(count)

Solution (Python):

A = int(input())
B = [int(x) for x in input().split()]
count = 1
tanking = 0
ans = 0
flag = False
for i in range(A):
    if B[i] == count:
        count += 1
        ans += tanking
        tanking = 0
        flag = True
    else: 
        tanking += 1
        if i == A-1:
            ans+= tanking

if not flag:print("-1")
else : print(ans)

Solution (Python):
import sys
N = int(input())
A = list(map(int, input().split()))
ans_lis = [1]

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

ans = 1
for i in range(N):
    if A[i] != 1:
        ans = ans + 1
    else:
        A = A[ans:len(A)]
        break
         
number = 1

for i in A:
    if number == (i-1) :
        ans_lis.append(i)
        number = i

print(N-(len(ans_lis)))

Solution (Python):
N = int(input())
L = list(map(int,input().split()))

index = 1
count = 0

for i in L:
  if i == index:
    index += 1
  else:
    count += 1
if count == N:
  count = -1
print(count)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def main():
    n = int(input())
    a = [int(_) for _ in input().split()]
    seek = 1

    for i in range(n):
        if a[i] == seek:
            seek += 1

    if seek == 1:
        ans = -1
    else:
        ans = n + 1 - seek

    print(ans)

if __name__ == '__main__':
    main()

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

cnt=0
c=1

for i in range(n):
  if a[i]!=c:
    cnt+=1
  else:
    c+=1
    
if cnt==n:
  print(-1)
else:
  print(cnt)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
res = 0
p = 1
for i in range(n):
    if a[i] == p:
        p += 1
    else:
        res += 1
if res == n:
    print(-1)
else:
    print(res)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
i=1
count=0

for a in A:
    if a==i:
        i+=1
    else:
        count+=1
if count==N:
    print(-1)
else:
    print(count)