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, *A = map(int, open(0).read().split())
    remaining = 0
    target = 1
    for i in A:
        if i == target:
            remaining += 1
            target += 1
    print(N - remaining if remaining else -1)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N, *A = map(int, open(0).read().split())
    remaining = 0
    cur = 0  
    for target in range(1, N + 1):
        be_kept = False
        for i in range(cur, N):
            if A[i] == target:
                remaining += 1
                cur = i + 1
                be_kept = True
                break
        if not be_kept:
            break
    print(N - remaining if remaining else -1)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
lst = [int(x) for x in input().split()]
i = 1
ret = 0
for x in lst:
    if x == i:
        i += 1
    else:
        ret += 1

if len(lst) == ret:
    print(-1)
else:
    print(ret)

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

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

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI()
    t = 1
    for c in a:
        if c == t:
            t += 1
    if t == 1:
        return -1

    return n - t + 1


print(main())

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

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

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

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

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

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

Solution (Python):
import math
import bisect
N = int(input())
c  = 0 
now = 1
nums = list(map(int,input().split(" ")))
for temp in nums:
    if temp == now:

        now += 1
    else:
        c += 1
if c == N: 
    print(-1)
else:
    print(c)

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

Solution (Python):
def main():
    N = int(input())
    lst = [int(s) for s in input().split()]
    if lst.count(1) < 1:
        print(-1)
        return
    current = 1
    for i in lst:
        if i == current:
            current += 1

    answer = N - current + 1
    print(answer)

if __name__ == "__main__":
    main()

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

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

if len(l) > 0:
  print(N - len(l))
else:
  print(-1)

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

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

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

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


num = 1
_index = None
num_index_list = []

for i in range(N):
    if original_list[i] == num:
        num_index_list.append([num, i])
        num += 1
    else:
        pass

time = N - len(num_index_list)

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

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

k = 1
S = 0

for a in A:
    if k == a:
        S += 1
        k += 1
if S:
    print(N-S)
else:
    print(-1)

Solution (Python):
n = int(input())
numbers = [int(i) for i in input().split(" ")]

now = 1

for i in range(n):
    
    if numbers[i]==now:
        now += 1

if now==1 and n>1:
    print(-1)
else:
    print(n-(now-1))

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

j=1
k=0
for i in a:
  if i==j:
    k+=1
    j+=1

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

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

Solution (Python):
def main():
    N = int(input())
    an = list(map(int, input().split(' ')))

    if not 1 in an:
        print('-1')
        return

    count = 1
    for a in an:
        if a == count:
            count += 1
    print(N - count + 1)

main()

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

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

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

cnt=1
for i in range(N):
  if Ar[i]==cnt:
    cnt+=1

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

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

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()))

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_N = list(map(int, input().split(' ')))
break_count = 0
remain_count = 1
for a_n in a_N:
    if a_n == remain_count:
        remain_count += 1
    else:
        break_count += 1
if break_count == N:
    print(-1)
else:
    print(break_count)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split(" ")))
    i = 1
    flag = True
    for a in A:
        if a == i:
            flag = False
            i += 1
    if flag:
        print(-1)
    else:
        print(len(A) - i + 1)


if __name__ == "__main__":
    main()

Solution (Python):
'''input
3 5
1 2 1
2 3 0
'''

from sys import stdin, setrecursionlimit
from bisect import bisect_left
import sys, threading



n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
k = 0
for i in range(n):
    if arr[i] == k + 1:
        k += 1

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

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

for i in range(N):
    if A[i] == c:
        c += 1
        
if c == 1:
  print(-1)
else:
  print(N-c+1)

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

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

c = 1
res = 0
for a in A :
    if c == a :
        c += 1
    else :
        res += 1

print(res if not res == n else -1)

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

num = 1
ans = 0

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

for i in range(n):
    a = A[i]
    if a == num:
        num += 1
        continue
    else:
        ans += 1
print(ans)

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

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


ans = []
count = 0
x = 1
for i in a:
    if x == int(i):
        x += 1
        ans.append(i)
    else:
        count += 1


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

Solution (Python):
numN = int(input())
input_line = input().split(' ')
brick = [int(i) for i in input_line]

seq = 0

for i, b in enumerate(brick):
  if b == 1:
    seq += 1
    cur = 2
    for c in brick[i + 1:]:
      if c == cur:
        seq += 1
        cur += 1
    break

if seq == 0:
  print(-1)
else:
  print(numN - seq)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
index = []
num = 1
tmp = 0
for i,a in enumerate(A):
    tmp += 1
    if a == num:
        index.append(i+1)
        num += 1
        tmp = 0
        continue
if num == 1:
    print(-1)
else:
    ans = index[0]-1
    for i in range(1, len(index)):
        ans += index[i] - index[i-1] - 1
    ans += tmp
    print(ans)

Solution (Python):
from collections import deque
N = int(input())
A = [int(x) for x in input().split()]
d = deque()
for i in range(N):
    d.append(A[i])
ans = 0
index = 1
if min(A) != 1:
    print(-1)
else:
    for i in range(N):
        left = d.popleft()
        if left == index:
            index += 1
        else:
            ans += 1
    print(ans)

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

num=1
for i in range(N):
    if num==A[i]:
        num+=1
    else:
        ans+=1
        
if N==ans:
    print(-1)
else:
    print(ans)

Solution (Python):
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

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

L = [int(v) for v in input().split()]





ans = 0
before = 1
for i in range(N):
    if L[i] != before:
        ans += 1
    else:
        before += 1

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

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

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

if sx > 1:
    print(delcnt)
else:
    print(-1)

Solution (Python):
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y
 
N=II()
xs=LI()
 
cur = 1
idx = 0
res = 0
for x in xs:
    if x == cur:
        cur += 1
    else:
        res += 1
if cur != 1:
    print(res)
else:
    print(-1)

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

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

next_break = 1
ans = 0
for a in A:
    if next_break == a:
        next_break += 1
    else:
        ans += 1

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

Solution (Python):
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
xs=LI()

cur = 1
idx = 0
res = 0
for x in xs:
    if x == cur:
        cur += 1
    else:
        res += 1
if cur != 1:
    print(res)
else:
    print(-1)

Solution (Python):
n = int(input())
l = list(input().split())

target_num = 1
for i in range(n):
  if target_num == int(l[i]):
    target_num += 1
  else:
    target_num = target_num

if target_num == 1:
  print("-1")
else:
  print(n - target_num +1)

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

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

ans = 0
cur = 1
for brick in bricks:
    if brick != cur:
        ans += 1
    else:
        cur += 1

if cur == 1:
    ans = -1

print(ans)

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

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

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

Solution (Python):
from sys import stdin
import fractions

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]


nex = 1
ans = 0

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

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

Solution (Python):

n=int(input())

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

Solution (Python):

n=int(input())

a=list(map(int,input().split()))
nex=1
ans=0
for i in range(n):
    if a[i]==nex:
        nex+=1
    else:
        ans+=1
if ans==n:
    print(-1)
    exit()
print(ans)

Solution (Python):
import sys
 
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  if a[i] == 1:
    break
  else:
    pass
else:
  print("-1")
  sys.exit()
j = 1
for i in range(n):
  if a[i] == j:
    j += 1
  else:
    pass
print(str(n-j+1))

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

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

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

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

Solution (Python):

import numpy as np
N = int(input())
A = np.array(input().split(), dtype=int)

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

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

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

now = 0
for x in a:
    if x == now + 1:
        now = x

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

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

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

count = 1
k = 0       

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

if k == n:
    k = -1

print(k)

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

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

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

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

    return N, renga


def solve(N, renga):
    ans = -1
    
    count = 0
    for i in range(N):
        if renga[i]==count+1:
            count+=1


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


if __name__ == '__main__':
    N, renga = read()
    
    solve(N, renga)

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

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

if curr == 1:
    print -1
else:
    print len(a) - curr + 1

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
c = 0

if 1 not in l:
    print(-1)
    exit(0)

searching_for = 1
for e in l:
    if searching_for == e:
        searching_for += 1
    else:
        c+=1

print(c)

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

key=1

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

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

Solution (Python):


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

def sol(N,a):
    nex = 1
    con = 0

    if  not 1 in a:
        return -1
    for i in range(N):
        if nex == a[i]:
            nex +=1
        else:
            con +=1
    return con
        
print(sol(N,a))

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

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

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


num=1
break_num=0

for i in L:
    if i!=num:
        break_num+=1
    else:
        num+=1

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

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

ans = n
for x in a:
    if x == k:
        k += 1
        ans -= 1

if ans == n:
    ans = -1

print(ans)

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

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

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

Solution (Python):
import collections
import bisect
N = int(input())
AL = list(map(int, input().split(" ")))

d = collections.defaultdict(list)
for index, num in enumerate(AL):
    d[num].append(index)

ans = 0
if not d[1]:
    print(-1)
else:
    current_pos = d[1][0]
    ans = 0
    for i in range(1, N+1):
        a = d[i+1]
        index = bisect.bisect_right(a, current_pos)
        if index != len(a):
            current_pos = a[index]
            continue
        else:
            ans = i
            break
    print(N - ans)

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    c = 0
    t = 1
    for i in range(n):
        if a[i] == t:
            c += 1
            t += 1
    print(n - c if c != 0 else -1)


if __name__ == '__main__':
    solve()

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

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

Solution (Python):
from sys import stdin
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
n = int(stdin.readline().rstrip())
ax = list(map(int, stdin.readline().rstrip().split()))

a = 1
i = 0
ans = 0
lim = True
while lim:
    if ax[i] != a:
        i += 1
        ans += 1
    else:
        i += 1
        a += 1
    if i == n:
        lim = False
    else:
        pass
if ans == n:
    print(-1)
else:
    print(ans)

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

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

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

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

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

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

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

start = 1
i = 0
while i < n:
    if a[i] == start:
        start += 1
        i += 1
    else:
        i += 1

start -= 1

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

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

Solution (Python):



if __name__=='__main__':
  n = int(input())
  a = list(map(int, input().strip().split()))
  current_number = 0
  for i in range(n):
    if a[i] == current_number+1:
      current_number+=1
  if current_number == 0:
    print(-1)
  else:
    print(n - current_number)

Solution (Python):



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

stair = 1
cnt = 0

for i in list : 
    if i == stair : 
        stair += 1
    else : 
        cnt += 1
        
if stair == 1 : 
    print(-1)
else : 
    print(cnt)

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

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

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

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

currnum = 1
breaknum = 0

for num in nums:
  if num == currnum:
    currnum = currnum + 1
    continue
  breaknum = breaknum + 1

print(-1 if breaknum == n else breaknum)

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

Solution (Python):
n, *a = map(int, open(0).read().split())
j, ans = 1, 0
for i in a:
    if i==j: j+=1
    else: ans+=1
print(ans if j!=1 else -1)

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

Solution (Python):
N = int(input())
*bricks, = map(int, input().split())

current = 0
order = 1
destroy = 0
while current < N:
    if bricks[current] == order:
        order += 1
    else:
        destroy += 1
    current += 1
else:
    print(destroy) if destroy < N else print(-1)

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

Solution (Python):
def run(N, a):
    ans = -1
    cnt = 0
    idx = 0
    i = 1
    match = False
    while idx < N:
        ai = a[idx]
        idx += 1
        if ai == i:
            
            match = True
            i += 1
        else:
            
            cnt += 1
    if match:
        ans = cnt
    return ans


def main():
    N = int(input())
    a = list(map(int, input().split()))
    print(run(N, a))


if __name__ == '__main__':
    main()

Solution (Python):
import fractions

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

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

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


if __name__ == '__main__':
    main()

Solution (Python):

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
    if a[i] == ans +1: ans +=1
if ans == 0: print(-1)
else: print(n - ans)

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

x = 1
for a in arr:
    if a == x:
        x += 1

print(n + 1 - x if x > 1 else -1)

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

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

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

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

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

result = 0
for i in range(N):
    if a[i] != (i-result):
        result += 1

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

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

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

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

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

if  not (1 in A):
  print(-1)
  exit()
  
cnt  = 1
for i in range(N):
  if A[i] == cnt:
    cnt +=1
print(N-(cnt-1))

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

i = 0
j = 0
bt = 0

while i < n:
  while j < n - i:
    if a[i+j] == i+1:
      bt += 1
      break
    if j + i == n-1:
      if i == 0:
        bt = -1
      j = n + 1
      i = n + 1
      
    j += 1
  i += 1
  
if bt != -1:
  bt = n - bt
  
print(bt)

Solution (Python):
n = int(input())
arra = input().split(' ')
for i in range(len(arra)):
    arra[i] = int(arra[i])
j = 1
num = 0
oldlen = len(arra)

buf =[0] * oldlen
for i in range(oldlen):
    if arra[i] != j:
        num += 1
        buf[i] = 1
    else:
        j += 1
for i in range(oldlen-1, -1, -1):
    if buf[i] == 1:
        del arra[i]
newlen = len(arra)
if newlen == oldlen:
    print(0)
elif num == oldlen:
    print(-1)
else:
    print(num)

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

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

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

Solution (Python):
length = int(input())
ary = [int(i) for i in input().split(' ')]

size = 0
for i in ary:
  if i == size + 1:
    size += 1
if size == 0:
  print(-1)
else:
  print(length - size)

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

num = 1
ans = 0

for i in A:
    if i == num:
        num += 1
    else:
        ans += 1

if num == 1:
    print('-1')
else:
    print(str(ans))

Solution (Python):
n = int(input())
m = list(map(int, input().split()))
ans = 0


if m == [i+1 for i in range(n)]:
    print(0)
elif 1 not in m:
    print(-1)
else:
    target = 1
    for i in m:
    
        if i == target:
            ans += 1
            target += 1

    print(n-ans)

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

num =  1
ans = 0
if 1 not in a:
    print(-1)
    sys.exit()
for i in a:
    if i == num:
        num += 1
    else:
        ans += 1
print(ans)

Solution (Python):
p=int(input())
k=input().split()
i2=1
i=0
while i<p:
    if i2==int(k[i]):
        i2+=1
    i+=1
if(i2==1):
    print(-1)
else:    
 print(p-(i2-1))

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

current = 0;

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

Solution (Python):
import sys

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

number = 1
count = 0

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

for num in nums:
    if num == number:
        number += 1
    else:
        count += 1
print(count)

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

cnt = 0
num = 1

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

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

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

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

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

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

Solution (Python):
if __name__ == "__main__":

    length = int(input())
    dataset = [int(x) for x in input().split()]
    last = dataset[-1] 

    pop_list = []
    i=0
    breaks=0
    for x in dataset:
        if x == i+1:
            i += 1
        else:
            breaks +=1
    
    if breaks>0 and i==0:
        print(-1)
    else:
        print(breaks)

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

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

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

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

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