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()))
cur = 0
for i in range(N):
    if A[i]==cur+1:
        cur += 1
if cur==0:
    print(-1)
else:
    print(N-cur)

Solution (Python):
def main():
    n=int(input())
    A=list(map(int,input().split()))
    c=0
    for a in A:
        if a==c+1:
            c+=1
    print(n-c if c else -1)
    
if __name__=='__main__':
    main()

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

Solution (Python):

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

ans = 0
noww = 1
for i in range(n):
    if aa[i] != noww:
        ans += 1
    else:
        noww += 1
if noww == 1:
    print(-1)
else:
    print(ans)

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):
from collections import Counter

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

next = 1
bricks = As

for i in range(n):
    if As[i] != next:
        bricks[i] = 0
    else:
        next += 1

ans = Counter(bricks)[0]

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

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

kosuu = 0
ima = 1

for a in A:
    if ima == a:
        ima += 1
        continue
    else:
        kosuu += 1

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

Solution (Python):
def run():
  N = int(input())
  a_li = list(map(int, input().split()))
  ans = 0
  i = 1
  for a in a_li:
    if a == i:
      i += 1
      continue
    else:
      ans += 1
  if ans == N:
    print(-1)
  else:
    print(ans)
  
if __name__ == '__main__':
  run()

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

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

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

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

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

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

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

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

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

cnt = 0
num = 1

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

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

Solution (Python):
N = int(input())
a = [int(x) for x in input().split()]
ans = 0
c = 1
tmp = 0
if 1 not in a:
    print(-1)
    quit()
for i in range(N):
    if a[i] == c:
        ans += i - tmp
        c += 1
        tmp = i+1
    elif i == N-1:
        ans += i - tmp + 1
print(ans)

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

res = [0]
for x in a:
    if x == res[-1]+1:
        res.append(x)

ans = n - len(res) + 1

if res == [0]:
    ans = -1

print(ans)

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

Solution (Python):


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

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

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

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

ans = 0
need = 1

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

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

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

s = 1

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
if min(a) > 1:
  print(-1)
  exit()

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

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
i = 0
k = 1
while i < n:
    if l[i] == k:
        k = k+1
        i = i+1
    else:
        i = i+1
if k == 1:
    print(-1)
else:
    print(n-k+1)

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

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

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

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

Solution (Python):

import sys


def solve(N: int, a: "List[int]"):

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

    if count == 1:
        print(-1)
    else:
        print(N - count + 1)
    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())
cnt = 0
A = list(map(int,input().split()))
ex = 1
for i in range(len(A)):
    if ex != A[i]:
        cnt += 1
    else:
        ex += 1
if cnt == len(A):
    print(-1)
else:
    print(cnt)

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

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

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

List=list(map(int,input().split()))
cnt = 1
ck = 0

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

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

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

c = 0

flag = False

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

if flag:
    print(n-c)
else:
    print(-1)

Solution (Python):


def main():
    N = int(input())
    rengas = [int(s) for s in input().split()]
    focus = 1
    count = 0
    for renga in rengas:
        if renga == focus:
            focus += 1
        else:
            count += 1
    result = count if count < len(rengas) else (-1)
    print(result)

if __name__ == "__main__":
    main()

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


count = 1
ans = 0
for a in A:
    if count == a:
        ans += 1
        count += 1

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

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

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

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
  else:
    cnt+=1
if cnt == n:
  print(-1)
else:
  print(cnt)

Solution (Python):


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

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

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

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

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

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

Solution (Python):
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd



def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


def main():
    N = I()
    a = LI()
    ans = 0
    temp = []

    for i in range(N):
        if len(temp) == 0 and a[i] == 1:
            temp.append(1)
        elif len(temp) != 0 and a[i] == temp[-1] + 1:
            temp.append(a[i])
        else:
            ans += 1

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


if __name__ == '__main__':
    main()

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

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

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

B = [i for i in range(1,N+1)]

index = 0
ans = 0
for i in range(len(A)):
    if A[i] == B[index]:
        index += 1
    else:
        ans += 1

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

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

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

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

Solution (Python):
def main():
    _ = int(input())
    a = list(map(int,input().split()))
    if 1 in a:
        x = 1
        ans = 0
        for i in a:
            if x == i:
                x += 1
            else:
                ans += 1
        print(ans)
    else:
        print(-1)
    
if __name__ == '__main__':
    main()

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

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

ans = 0
index = 1

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

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

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

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

K = 0
for num in A:
    if num == K+1:
        K+=1

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

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

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

ans=N-se+1
if se==1:
    ans=-1
print(ans)

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

ans = 0
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):
import sys,collections,math,random;sys.setrecursionlimit(10**7)
from fractions import gcd
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n =I()
lis = Is()
i = 1
for e in lis:
    if e == i:
        i += 1
if i == 1:
    print(-1)
else:
    print(n-i+1)

Solution (Python):
import sys
N = int(input())
A = [int(i) for i in input().split()]
if not 1 in A:
    print(-1)
    sys.exit()
tmp = 1
cnt = 0

for i in range(N):
    if tmp != A[i]:
        cnt += 1
    else:
        tmp += 1
print(cnt)

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

idx = 1
count = 0
flag = False
for i in range(n):
  if a[i] == idx:
    flag = True
    idx+=1
  else:
    count+=1
   
if flag:
  print(count)
else:
  print(-1)

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

cnt = 1
ans = 0

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

print(ans if cnt > 1 else -1)

Solution (Python):
from fractions import gcd

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A):
    current_brick = 1
    break_count = 0
    for i in range(N):
        if current_brick == A[i]:
            current_brick += 1
        else:
            break_count += 1
    if break_count == N:
        return -1
    return break_count


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline






















def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	A = inputList()

	ans = 0
	tmp = 1
	for i,val in enumerate(A):
		if val == tmp:
			tmp += 1
		else:
			ans += 1

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

if __name__ == "__main__":
	main()

Solution (Python):
import sys, math
from collections import defaultdict
from copy import deepcopy
import itertools
input = sys.stdin.readline




N = int(input())
A = [0] + list(map(int, input().split()))
s = 0
destroyed = 0
for i in range(N + 1):
    if A[i] == s:
        s += 1
    else:
        destroyed += 1

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

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

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

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

if A.count(1)==0:
    print(-1)
    exit()
x=1
for i,a in enumerate(A):
    if a==x:
        x+=1


print(N-x+1)

Solution (Python):
N = input()

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


left_count = 1
count = 0

for a in A:
    if a == left_count:
        left_count += 1
    else:
        count += 1
if left_count > 1:
    print(count)
else:
    print(-1)

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

    if 1 not in A:
        return -1

    most_left_one = A.index(1)
    ans = most_left_one
    current = 1
    for i in range(most_left_one, N):
        if current == A[i]:
            current += 1
        else:
            ans += 1
    return ans

print(d_brick_break())

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

target = 1
find = False
for i in range(N):
    if A[i] == target:
        find = True
        target += 1

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

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

Solution (Python):


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

Solution (Python):
n = int(input())
L = list(map(int, input().split()))
counter = 1
br = 0
import sys
if 1 not in L:
  print(-1)
  sys.exit()

for num in L:
  if num != counter:
    br += 1
  if num == counter:
    counter += 1
print(br)

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

Solution (Python):
N = int(input())
A = [int(a) for a in 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 = list(map(int, input().split()))

count = 1
ans = 0
for a in a_list:
    if a != count:
        ans += 1
    else:
        count += 1

if(count == 1):
    ans = -1

print(ans)

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

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

Solution (Python):

N=int(input())

a=[int(i) for i in 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()))
cur=1
for e in a:
    if e==cur:
        cur+=1
cur-=1
if cur:
    print(n-cur)
else:
    print(-1)

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

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

K = 0
for ai in a:
    if ai == K + 1:
        K += 1
print(N - K if K > 0 else -1)

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline






















def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	A = inputList()

	ans = 0
	tmp = 1
	for i,val in enumerate(A):
		if val == tmp:
			tmp += 1
		else:
			ans += 1

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

if __name__ == "__main__":
	main()

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


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


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
cnt = 0
now = 0
for x in a:
	if x == now+1:
		now+=1
		continue
	cnt+=1

if 1 in a:
	print(cnt)
else:
	print(-1)

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

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

n_break = 0
target = 1
nums = map(int, input().split(" "))

for num in nums:
    if num == target: 
        target += 1
    else:
        n_break += 1

if n_break == n:
    out = -1
else:
    out = n_break
print(out)

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

ans = 0
j = 0

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

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

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

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

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

i = 1
r = 0
while r < N:
  if A_list[r] == i:
    i += 1
    r += 1
  else:
    r += 1

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

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

if a.count(1) == 0:
    print(ans)
    exit()

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

print(N - (index - 1))

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

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

ans = 0
cur = 1
last = 0

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

    print(ans + last)

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

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

print(ans if ans < N else -1)

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

cnt = 1
ans = 0
for ai in a_list:
    if ai == cnt:
        cnt += 1
    else:
        ans += 1

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

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

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

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

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

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

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

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
br = list(map(int, stdin.readline().rstrip().split()))
cur = 0
for i in br:
    if i == cur + 1:
        cur = i
if cur == 0:
    print(-1)
else:
    print(n - cur)

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines







def main():
	n=int(input())
	A=list(map(int,input().split()))
	cnt=1
	
	for i in A:
		if i==cnt:
			cnt+=1
	cnt-=1
	
	ans=len(A)-cnt
	
	if cnt==0:
		ans=-1
	print(ans)
	
	




	
if __name__ == "__main__":
	main()

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

index = 1
ans = 0
flag = 0
for i in range(1,N+1):
  if A[i-1] == index:
    flag = 1
    index += 1
  else:
    ans += 1

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

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

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

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

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

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

ans = 0
checker = 1

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

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

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

now = 1
doubt = 0
ans = 0
for i in range(N):
  if A[i] == now:
    now += 1
    doubt = 1
  else:
    ans += 1
    
if doubt == 0:
  print("-1")
else:
  print(ans)

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


if A == [1]:
    print(0)
else:
    ans = 0
    cnt = 1
    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()))
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())
As = list(map(int, input().split()))

search = 1
cnt = N
for a in As:
    if a == search:
        search += 1
        cnt -= 1

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

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

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

ans=0
j=1
for i in a:
    if i == j:
        j+=1
    else:
        ans+=1
print(ans)

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

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

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

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

i = 0
answer = 0

while answer + i < N:
    if A[answer+i] == i:
        i += 1
    else:
        answer += 1

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

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

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

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

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

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

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

count = 0
num = 1
for brick in bricks:
  if brick != num:
    count += 1
  else:
    num += 1
    
print(count if count != len(bricks) else -1)

Solution (Python):
import fractions as fc

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

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

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

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

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

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

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

counter = 1

ans = 0

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

if ans == len(A):
    print(-1)
else:
    print(ans)

Solution (Python):
import sys
from fractions import *

stdin = sys.stdin

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

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

Solution (Python):

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

i = 1
b = 0

for ai in an:
    if ai == i:
        i += 1
    else:
        b += 1

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

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

tmp = 1
ans = 0

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

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

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

table = collections.defaultdict(int)
m = 0
for i in range(N):
    table[a[i]] += 1
    if a[i] == m or a[i] == m+1:
        m = a[i]
if m == 0:
    print(-1)
else:
    print(N - m)

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