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):
N = int(input())
a = list(map(int, input().split()))

i = 1
ans = 0
for aa in a:

    if aa != i:
        ans += 1
    else:
        i += 1

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

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

card = 1
cnt = 0

for i in a:
  if i == card:
    card += 1
  else:
    cnt += 1

if cnt == n:
  print('-1')

else:
  print(cnt)

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

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

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

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

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

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

Solution (Python):
import math

n = int(input())
aL = list(map(int, input().split(" ")))

crnt = 1
for a in aL:
    if a == crnt:
        crnt += 1

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

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
i=0
n=1
while True:
  if i==N:
    break
  if L[i]==n:
    n+=1
  i+=1
if n==1:
  print(-1)
else:
  print(N-n+1)

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    n = ini()
    a = inl()
    cur = 1
    for x in a:
        if x == cur:
            cur += 1
    if cur == 1:
        return -1
    return n + 1 - cur


print(solve())

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

m = 1
count = 0
for i in range(n):
    if a[i] != m:
        count += 1
    else:
        m += 1
print(count if count < n else -1)

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

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

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

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

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

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7


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

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

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
if not 1 in set(a):
    print("-1")
    exit()
b=1
for i in range(n):
    if a[i]==b:
        b+=1
print(n-b+1)

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

for i in map(int, input().split()):
    if i == j:
        j += 1

print((-1, n - j + 1)[j != 1])

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
if 1 not in a:
  print(-1)
  exit()
num_break = 0
pos = 1

for i in a:
  if i == pos:
    pos += 1
  else:
    num_break += 1
print(num_break)

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush

sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = inpl()

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

else:
    i = 1
    for a in A:
        if i != a:
            ans += 1
        else:
            i += 1

print(ans)

Solution (Python):


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

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

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

Solution (Python):

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

num = 1
count = 0
for i in range(N):
    if a[i] == num:
        num += 1
    else:
        count += 1
result = count
if result == N:
    result = '-1'
print(result)

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

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

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

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

Solution (Python):




def resolve():
    import sys
    input = sys.stdin.readline

    n = int(input().rstrip())

    count = 0
    ans = 0
    for a in input().rstrip().split(" "):
        a = int(a)
        if a == count + 1:
            count+= 1
        else:
            ans += 1

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

if __name__ == "__main__":
    resolve()

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

Solution (Python):
n = int(input())
Al = list(map(int, input().split()))
cnt= 1

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

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

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

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

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

tmp = 1
s = set()
for x in a:
  if x == tmp:
    s.add(x)
    tmp += 1

print(n - len(s) if s else -1)

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

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

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

Solution (Python):
def main():
    N = int(input())
    b = list(map(int, input().split()))
    i = 1

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

if __name__ == '__main__':
    main()

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()))
ans=[0]*n
c=1
for i in range(n):
  if a[i]==c:
    ans[i]=1
    c+=1
if sum(ans)==0:
  print(-1)
else:
  print(n-sum(ans))

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

Solution (Python):

n = int(input())

a = list()
a = input().split()

curr = 1
count = 0

for i in a:
    if int(i) == curr: 
        curr+=1
    elif int(i)!=curr:
        count+=1
if curr == 1:
    print("-1")
else:
    print(count)

Solution (Python):
n = int(input())
a = [1e6] + list(map(int, input().split()))
cnt = 1
exist = False
for i in a:
    if i == cnt:
        exist = True
        cnt += 1
cnt -= 1

if exist:
    print(n - cnt)
else:
    print(-1)

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

ans = 0
next = 1

for a in a:
    if a == next:
        next += 1
    else:
        ans += 1

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

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

cnt = 1
for x in arr:
    if cnt == x:
        cnt = cnt + 1
if cnt == 1:
    print(-1)
else:
    print(n-cnt+1)

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in a:
  if 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
now = 1
for i in range(N):
	if A[i] == now:
		now += 1
		continue
	else:
		ans += 1
if now == 1 and ans == N:
	print(-1)
else:
	print(ans)

Solution (Python):


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


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

count = 0
pos = 1
for i, a in enumerate(A):
    if a == pos:
        pos += 1
    else:
        count += 1

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

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

Solution (Python):
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

cnt = 1
ans = 0

for a in A:
    if a != cnt:
        ans += 1
        continue
    else:
        cnt += 1

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

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

k=0
bc=0
c=0
i=0
while k < n :
    if P[k]!=i+1 :
        bc+=1
    else:
        i+=1
        c+=1
    k+=1

if c==0 :
    bc = -1

print(bc)

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

ans=n-res2+1 if res else -1
print(ans)

Solution (Python):
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

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

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

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

Solution (Python):
N = int(input())
A = tuple(map(int, input().split()))
x = [[] for _ in range(N + 1)]
for i, a in enumerate(A):
    x[a].append(i)

maxcount = 0
todo = [(1, i) for i in x[1]]
while todo:
    a, i = todo.pop()
    maxcount = max(maxcount, a)
    if a == N:
        continue
    na = a + 1
    for ni in x[na]:
        if ni < i:
            continue
        todo.append((na, ni))
if maxcount > 0:
    print(N - maxcount)
else:
    print(-1)

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

while x <= N - 1:
    if ans + 1 == a[x]:
        ans += 1
    x += 1
    
if ans == 0:
    print(-1)
else:
    print(N - ans)

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

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

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

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

t = 1

s = 0

if t not in a:
    s = -1
else:
    for x in a:
        if x == t:
            t += 1
        else:
            s += 1

print(s)

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

num = 1

res = 0

for a in A:
    if a == num:
        num += 1
    else:
        res += 1


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

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')


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


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

Solution (Python):
from collections import deque
N = int(input())
a = list(map(int,input().split()))
d = deque()
for i in range(1,200001):
  d.append(i)
count=0
for i in a:
  if i==d[0]:
    count+=1
    d.popleft()
    
if count==0:
  print(-1)
else:
  print(N-count)

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

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

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

cnt = 0
now = 0
for a in A:
  if a == now + 1:
    now += 1
  else:
    cnt += 1

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

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

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

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

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

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

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

Solution (Python):
n=int(input())
inp=list(map(int,input().split()))
from collections import Counter
z=0
k=1
for i in range(len(inp)):
    if inp[i]==k:
        z+=1
        k+=1
if z==0:
    print (-1)
else:
    print (len(inp)-z)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
i=1
f=False
for ai in a:
    if ai==i:
        i+=1
        f=True

if f:
    print(N-i+1)
else:
    print(-1)

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

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

aset = set(a)
if 1 not in aset:
    print(-1)
else:
    nex = 1
    counter = 0
    for i in range(N):
        if a[i] == nex:
            nex += 1
        else:
            counter += 1
    print(counter)

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

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

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

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

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

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

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)
    exit()
print(N - num + 1)

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

check=1
ans=0

ans_flag=False

for a in A:
    if a==check:
        ans_flag=True
        check += 1
        
    else:
        ans += 1
        
if ans_flag == False:
    ans=-1
    
print(ans)

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

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

j = 1
ans = 0

for i in a:
    if i == j:
        j += 1
    else:
        ans += 1

if j == 1:
    print('-1')
else:
    print(ans)

Solution (Python):
import math
import sys
import bisect
readline = sys.stdin.readline


def main():
    n = int(readline().rstrip())
    A = list(map(int, readline().rstrip().split()))
    k = 0

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

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

    print(n - k)


if __name__ == '__main__':
    main()

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

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

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

    

if '__main__' == __name__:
    resolve()

Solution (Python):
x=int(input())
s=list(map(int,input().split()))
p=0
c=1
for n in s:
    if n==c:
        c+=1
        p+=1

if p==0:
    print(-1)
    exit(0)
print(x-p)

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

flag = False
b = []
cnt = 1
for i in range(n):
    if a[i] == cnt:
        flag = True
        b += [i]
        cnt += 1

if not flag:
    print(-1)
    sys.exit()

print(n - len(b))

Solution (Python):
N = int(input())
A = input().split(' ')
A = [int(A[i]) for i in range(N)]
NN = 1
count = 0
check = []
for i in range(N):
  if not A[i] == NN:
    count += 1
  else:
    check.append(A[i])
    NN += 1
if not check:
  print(-1)
else:
  print(count)

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

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

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

num = 0
for item in a:
    if item == (num + 1):
        num += 1

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

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

def main(n,a):
    tgt=1
    count=0
    for i in range(n):
        if a[i]==tgt:
            tgt+=1
        else:
            count+=1
    if count==n:
        return -1
    else: 
        return count

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)

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

i = 1
ans = 0
red = []
for a in A:
    if a == i:
        red += [i]
        i += 1
    else:
        ans += 1
if not ans == len(A):
    print(ans)
else:
    print(-1)

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

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

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

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

step = 1

for i in range(len(ai)):
    if ai[i] != step:
        ai[i] = 0
    else:
        step += 1

if sum(ai) == 0:
    print(-1)
else:
    print(ai.count(0))

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

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

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
_a = LI()


a = np.array(_a)


if not np.amin(a)==1:
    print(-1)
    exit()

maxNumber = 1

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

print(N - (maxNumber-1))

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

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

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))[::-1]
number=2
if 1 not in a: print(-1);exit()
count=n-len(a[:a.index(1)+1])
a=a[:a.index(1)][::-1]
for i in a:
  if i==number:
    number+=1
  else:
    count+=1
print(count)

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

manzoku = 1
hakai = 0

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

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

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

for p in range(N):
    if A[p] == n+1:
        n += 1

if n != 0:
    print(N-n)
else:
    print(-1)

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

ni = 1
remains = 0

for r in renga:
    if ni == r:
        ni += 1
        remains += 1
if ni == 1:
    print(-1)
else:
    print(len(renga) - remains)

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

cnt = 1
broken = 0
for a in A:
  if a == cnt:
    cnt += 1
  else:
    broken += 1

if cnt == 1:
  print("-1")
else:
  print(broken)

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

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

ans=0
ch=1

for x in range(n):
  if a[x]==ch:
    ans+=1
    ch+=1
    
if ans==0:
  print(-1)
else:
  print(n-ans)

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

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

bcnt = 0
signal = 1

for i in a:
    if i == signal:
        signal += 1
    else:
        bcnt += 1

if bcnt == N:
    print('-1')
else:
    print(bcnt)

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

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

if is_not_minus:
    print(n - order_counter + 1)
else:
    print(-1)

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

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

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
cnt=0
if 1 not in a:
    print(-1)
    exit()
else:
    num=1
    for i in range(n):
        if a[i]==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()))
i=1
ans=0
for x in A:
  if x==i:
    i += 1
  else:
    ans += 1
if ans==N:
  ans=-1
print(ans)

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

k = 1
ans = 0

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

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

print(ans)

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

Solution (Python):
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
if 1 not in a:
  ans=-1
print(ans)

Solution (Python):
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
if ans==n:
  ans=-1
print(ans)

Solution (Python):
N = int(input())
Ali = list(map(int,input().split()))
s = 1
res = 0

for i in range(N):
  if Ali[i] == s:
    s += 1
  else:
    res += 1
    
if s == 1:
  print(-1)
else:
  print(res)

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

Solution (Python):

from sys import exit

def main():
  N = int(input())
  a = list(map(int,input().split()))
  index = -1
  num = 1
  
  for i in range(index+1, N):
    if a[i] != num:
      continue
    elif a[i] == num:
      index = i
      num += 1
      
  if index != -1:
    print(N-(num-1))
    exit()
      
  
  print(index)
  
  
  
  
main()

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


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













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

  print(N-max_ if max_ else -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(readline())

p = list(map(int, readline().split()))

num = 1
l = []
for i in range(n):
    if p[i] == num:
        l.append(i)
        num += 1

print('-1' if len(l) == 0 else n-len(l))

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

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

if N==1 and A[0]==1:
  print(0)
elif 1 not in A:
  print(-1)
else:
  print(ans)

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

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

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

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

print(cnt) if a.count(1) else print(-1)

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

ans = 1
a = 0

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

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

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

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

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

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

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

print(N - cnt if target != 1 else -1)

Solution (Python):
import os, sys, re, math
from functools import reduce

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

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

if v > 1:
    print(count)
else:
    print(-1)

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

Solution (Python):
N = int(input())
A = [int(s) for s in input().split(' ')]
head = 1
count = 0
for a in A:
    if a == head:
        head += 1
        continue
    else:
        count += 1
if head == 1:
    print(-1)
else:
    print(count)

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

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

Solution (Python):
n = int(input())
aas = list(map(int, input().split()))
if n == 1 and aas == [1]:
    print(0)
    exit()
t = 0
for i in aas:
    if i == t + 1:
        t += 1
print(n-t if t > 0 else -1)

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

i = 1
n = 0
for a in A:
    if a == i:
        i += 1
    else:
        n += 1

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