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):
import math
from collections import deque
from collections import defaultdict
import itertools as it


def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): 
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): 
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} 
def bitArr(n):
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): 
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	
	ans = data[:]
	return ans

n = readInt()
a = readInts()

ans = 10*10
ans = 0
for i in a:
	if ans+1==i:
		ans+=1

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

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

def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    mark = 1
    remain = 0
    for i in range(n):
        if a[i] == mark:
            remain += 1
            mark += 1
    if remain == 0:
        print(-1)
    else:
        print(n-remain)

if __name__ == '__main__':
    main()

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

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

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

next_target = 1

idx = []

for i, a in enumerate(A):
    if a == next_target:
        idx.append(i)
        next_target += 1

if not idx:
    print(-1)
else:
    prev = -1
    sum_ = 0

    if idx[-1] != N - 1:
        sum_ += N - (idx[-1] + 1)

    for x in idx:
        sum_ += x - prev - 1
        prev = x

    print(sum_)

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

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

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

Solution (Python):
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)

from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction



def main():
    num = int(input())
    data = list(map(int, input().split()))

    now_ind = 1
    break_num = 0

    for i in range(num):
        if data[i] == now_ind:
            now_ind += 1
        else:
            break_num += 1

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



if __name__ == '__main__':
    main()

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

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

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

print(cnt)

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

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

Solution (Python):
import sys
from io import StringIO
import unittest
import os



def resolve():
    
    
    
    n = int(input())
    bricks = list(map(int, input().split()))

    
    if 1 not in bricks:
        print(-1)
        return

    num = 1
    ban = 0
    for brick in bricks:
        if brick == num:
            num += 1
            continue
        ban += 1

        
        1 == 1

    print(ban)





    
    
    pass



class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """3
2 1 2"""
        output = """1"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """3
2 2 2"""
        output = """-1"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """10
3 1 4 1 5 9 2 6 5 3"""
        output = """7"""
        self.assertIO(test_input, output)

    def test_input_4(self):
        test_input = """1
1"""
        output = """0"""
        self.assertIO(test_input, output)

    
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)



if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        
        resolve()

    else:
        
        unittest.main()

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
    continue
  cnt += 1

print(cnt if num > 1 else -1)

Solution (Python):
import sys
import itertools

import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

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

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

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

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

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

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

nxt = 1
broken = 0
for i in range(n):
  if B[i]==nxt:
    nxt += 1
  else:
    broken += 1
    
if broken==n:
  print(-1)
else:
  print(broken)

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

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

cnt = 0
cur = 1
for i in A:
  if i == cur:
    cur += 1
  else:
    cnt += 1

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

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

res = 0
idx = 1
for v in a:
    if v == idx:
        idx += 1
    else:
        res += 1

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

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

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

if 1 not in a:
    ans = -1
    print(ans)
else:
    broken = []
    survived = []
    latest = 1
    for i in range(1,N+1):
        if a[i] != latest:
            broken.append(a[i])
        else:
            latest += 1
            survived.append(a[i])
    print(len(broken))

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

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

count = []
n_count = 0
now_num = 1

for i in range(N):
  if a[i] == now_num:
    n_count += 1
    now_num += 1
else:
  if n_count != 0:
    count.append(i - (n_count - 1) + N - (i + 1))
    
if count:
  print(min(count))
else:
  print(-1)

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

print(N-x+1 if x != 1 else -1)

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

cnt = 0
now = 1
for i, v in enumerate(a):
    if v == now:
        now += 1
        continue
    else:
        cnt += 1

print(cnt if cnt != len(a) else -1)

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

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

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    tmp = 1
    for i in range(n):
        if a[i] == tmp:
            tmp +=1
        else:
            ans += 1
    if ans == n and n != 1:
        print(-1)
    else:
        print(ans)
    
      
if __name__ == '__main__':
    main()

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

now=1
for x in a:
  if x==now:
    now+=1
if now==1:
  now=N+2
print(N-now+1)

Solution (Python):
N=int(input())
S=list(map(int,input().split()))
first=len(S)
count=0

mokuteki=1
block=0
while count<N:
    if S[count]!=mokuteki:
        
        block+=1
    else:
        mokuteki+=1
        
    count+=1

if mokuteki>1:
    print(block)
else:
    print(-1)

Solution (Python):
N=int(input())
S=list(map(int,input().split()))
first=len(S)
count=0
pos=0
mokuteki=1
block=0
while count<N:
    if S[pos]!=mokuteki:
        pos+=1
        block+=1
    else:
        mokuteki+=1
        pos+=1
    count+=1

if mokuteki>1:
    print(block)
else:
    print(-1)

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

for i in range(len(A)):
    if A[i]==number_count:
        number_count+=1
    else:
        ans_count+=1
        
if number_count!=1:print(ans_count)
else:print("-1")

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

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

Solution (Python):
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

n = I()
a = Intl()
cnt = 0
if not 1 in a:
    print(-1)
    exit()
now = 1
for i in range(n):
    if now == a[i]:
        now += 1
    else:
        cnt += 1
print(cnt)

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

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

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
    
if count==0:
  print(-1)
else:
  print(N-count)

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

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

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

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

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

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

break_count = 0
index = 1
for a_i in a:
    if a_i == index:
        index += 1
    else:
        break_count += 1
if index == 1:
    print(-1)
else:
    print(break_count)

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

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

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

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

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

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

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

for a in A:
  if a == num:
    num += 1
  else:
    ans += 1
    
if ans == n:
  print("-1")
else:
  print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)  
to_index = lambda x: int(x) - 1  
print_list_in_2D = lambda x: print(*x, sep="\n")  


def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

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

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())


def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))


def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N = input_int()
a_list = LII_split()

ans = 0

current_idx = 0
continuous_cnt = 0

for i in range(1, N + 2):

    while current_idx < N:
        if a_list[current_idx] == i:
            continuous_cnt += 1
            break
        else:
            current_idx += 1
    if i == 1 and continuous_cnt == 0:
        break

print(N - continuous_cnt if continuous_cnt > 0 else -1)

Solution (Python):
n=int(input())
a=[int(x) for x in input().rstrip().split()]
cnt=0
now=0
for i in range(n):
  while(now<n):
    if a[now]==i+1:
      cnt+=1
      break
    else:
      now+=1

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

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

    ans = 0
    tmp = 1
    for aa in a:
        if aa == tmp:
            tmp += 1
        else:
            ans += 1

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


if __name__ == "__main__":
    main()

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

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

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

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

n = 1
for x in A:
    if x == n:
        n += 1
 
answer = N - n + 1
if answer == N:
    answer = -1
print(answer)

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

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

now = 1
for x in a:
  if x == now:
    now += 1
    
print(-1 if now == 1 else n-now+1)

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:
    print(-1)
else:
    print(ans)

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

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

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

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

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

Solution (Python):
N = int(input())
a_list = list(map(int, input().split()))
dp = [0]*N

if 1 not in a_list:
    print(-1)
else:
    dp[0]= 1
    count = 0
    for i in range(N-1):
        if dp[i] == a_list[i]:
            dp[i + 1] = dp[i] + 1
        else:
            dp[i + 1] = dp[i]
            count += 1

    if dp[N-1] != a_list[N-1]:
        count += 1
        
    print(count)

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

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

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

next = 1
ans = 0
found = False
for i in range(N):
    if A[i] == next:
        next += 1
        found = True
    else:
        ans += 1

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

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

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

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

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

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

Solution (Python):
import sys

input = lambda: sys.stdin.readline().rstrip()


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

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

    if bl == 1:
        print('-1')
    else:
        print(N - bl + 1)


if __name__ == '__main__':
    solve()

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

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



import sys




def input():
    return sys.stdin.readline().rstrip('\n')

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

count = 1

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

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

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)








n=n0()
A=n1()

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

Solution (Python):
n=int(input())
lis=list(map(int,input().split()))
ans=0
base=1
for i in lis:
    if i==base:
        base+=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 ai in a:
  if ai==cnt:
    cnt+=1
print(n-(cnt-1) if cnt>1 else -1)

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

if A.count(1)==0:
  print('-1')
  exit()
  
ans=0
j=1

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

Solution (Python):
def main():
    n, *a = map(int, open(0).read().split())
    
    g = 0
    t = 1
    for x in a:
        if x == t:
            t += 1
        else:
            g += 1

    print(g if g != n else -1)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from collections import deque
    n, *a = map(int, open(0).read().split())
    a = deque(a)

    tar = 1
    gab = 0
    while a:
        i = a.popleft()
        if i != tar:
            gab += 1
        else:
            tar += 1

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


if __name__ == '__main__':
    main()

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):
N = int(input())
An = list(map(int, input().split()))
done = 0
for i in An:
    if done+1 == i:
        done = i
if done == 0:
    print(-1)
else:
    print(N-done)

Solution (Python):
n = int(raw_input())
elems = map(int,raw_input().split(' '))
wanted = 1
for e in elems:
	if e == wanted:
		wanted+=1
need= n - (wanted -1)
print need if need < n else -1

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

a = list(map(int,input().split()))
l = []

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

s = 0
cnt = 0
for i in a:
    if i == s + 1:
        l.append(i)
        s = i
    else:    
        cnt += 1

print(cnt)

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

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

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

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

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

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

Solution (Python):













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

def calculate(n,arr):
    currentSearchIndexs = []
    currentSearch = 1
    for i in range(n):
        if arr[i] == currentSearch:
            if len(currentSearchIndexs) < currentSearch:
                currentSearchIndexs.append(i)
            else:
                currentSearchIndexs[currentSearch-1] = i

            currentSearch = currentSearch  + 1



    if len(currentSearchIndexs) == 0:
        print(-1)
        return

    print(n - len(currentSearchIndexs))

calculate(N,ARR)

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

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

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

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

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

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

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

Solution (Python):
from collections import deque
N = int(input())
A = deque(map(int, input().split()))
num = 1
ans = 0
while A:
  a = A.popleft()
  if a == num:
    num += 1
  else:
    ans += 1
print(-1 if num == 1 else ans)

Solution (Python):
import sys
import  math
from heapq import *
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()
now=1
for i in range(N):
    if(A[i]==now):
        now+=1

if(now==1):
    print(-1)
    sys.exit()

print(N-now+1)

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

Solution (Python):
from collections import deque
n=int(input())
a=list(map(int,input().split()))
ad=deque(a)
tmp=1
ans=0
while ad:
    if ad[0] ==tmp:
        tmp+=1
        ad.popleft()
    else:
        ad.popleft()
        ans+=1
if tmp==1 and ans>0:
    print(-1)
else:
    print(ans)

Solution (Python):

import math


def inp():
    return(int(input()))



def inlist():
    return(list(map(int, input().split())))



def instr():
    s = input()
    return(list(s[:len(s)]))



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


N = inp()

a = inlist()

look = 1
removed = 0
for i in range(N):
    if a[i] != look and removed < N-1:
        removed += 1
    else:
        if a[i] == look:
            look += 1
if look == 1:
    print(-1)
else:
    print(removed)

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

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

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

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

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

total=0
num=1
for j in range(N):
    if A[j]!=num:
        total+=1
    else:
        num+=1
if total==N:
    print(-1)
else:
    print(total)

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

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

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

Solution (Python):

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

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

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

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

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
cnt = 0
check = 1

for i in A:
  if i == check:
    cnt += 1
    check += 1

if cnt == 0:
  print(-1)
else:
  print(len(A) - cnt)

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

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

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

find_num=1
break_num=0
flag = False
for i in range(n):
    if a[i] == find_num:
        find_num+=1
        flag = True
    else:
        break_num+=1

if flag:
    print(break_num)
else:
    print(-1)

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

ans = 0
current = 1
flag = False

for a in a_list:
    if a != current:
        ans += 1
    else:
        current += 1
        flag = True

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

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

ans = 0
current = 1
flag = False
for a in a_list:
    if a != current:
        ans += 1
    else:
        current += 1
        flag = True
if flag:
    print(ans)
else:
    print(-1)