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())
l = list(map(int, input().split()))
ans = 0
num = 1
old_i = 0
for i in range(n):
    if l[i] == num:
        
        ans += (i - old_i)
        old_i = i + 1
        num += 1
ans += (i - old_i + 1)
if num == 1:
    print(-1)
else:
    print(ans)

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

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

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

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

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

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

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

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

tmp = 0
count = 0

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

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

p = 0
c = 1
i = 0
ans = 0
while i < n:
    if a[i] == c:
        p = i + 1
        c += 1
    else:
        ans += 1

    i += 1



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

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

print(result)

Solution (Python):

import sys
import os

def problem148D(N, alist):
  index = 0
  count = 0
  number = 1
  while index < N:
    if alist[index] == number:
      number += 1
    else:
      count += 1
    index += 1
  if count == N:
    count = -1
  print(count)

if __name__ == "__main__":
  N = int(input())
  alist= list(map(int, input().split()))
  problem148D(N, alist)

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

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

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

k = 1
cnt = 0

for i in range(n):
    if ls_a[i] != k:
        cnt += 1
    elif ls_a[i] == k:
        k += 1

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

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

c = 1
cp = 0

for i in range(N):
  ai = an[i]
  if ai != c:
    cp += 1
    
  elif ai == c:
    c += 1
    
if N == cp:
    cp = -1

print(cp)

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

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

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

print("{}".format(answer))

Solution (Python):


''' 
------------------------
author : iiou16
------------------------
'''


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

    count = 0
    id = 1

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


if __name__ == '__main__':
    main()

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

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


counter = 0
target = 1
for i in range(len(nums)):
    if nums[i] != target:
        counter += 1
    else:
        target += 1
        continue
if target == 1:
    print(-1)
else:
    print(counter)

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

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

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

Solution (Python):


N = int(input())

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

cnt = 1
ans = 0

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

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

Solution (Python):

import numpy as np

n = int(input())
a = np.array(input().split(), dtype='int')

j = 1

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

ans = n - j + 1

if ans == n:
    ans = -1

print(ans)

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

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

Solution (Python):
import sys
from collections import deque
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().strip().split()]
t = 0
f = 1
ans = deque([])

for n, a in enumerate(A, start=1):
    if a == f:
        ans.append(n - t - 1)
        f += 1
        t = n
else:
    if t != N:
        ans.append(n - t)

if f == 1:
    print(-1)
else:
    print(sum(ans))

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

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
i=0
b=0
X=1
while i<N:
  if a[i]==X:
    X+=1
  else:
    b+=1
  i+=1
if b==N:
  b=-1
print(b)

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

ans = []
count = 0
q = 1

for a in arr:
	if a == q:
		q += 1
		ans.append(a)
	else:
		count += 1

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

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

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

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

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

Solution (Python):

import sys
input = sys.stdin.readline

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

k = 1

seta = set(a)
if k not in seta:
    print(-1)
    sys.exit()

res = 0

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

print(res)

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

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

Solution (Python):
import sys
sys.setrecursionlimit(2000000)

n=int(input())
a=[]*n
a=list(map(int,input().split()))
num=1
bre=0
no=True
def search(pos):
    spos=pos
    global num,bre,no
    end=True
    while end:
        if spos >= n:
            break
        if a[spos]==num:
            no=False
            num+=1
            search(spos+1)
            end=False
        else:
            spos+=1
            bre+=1

search(0)
if no:
    bre=-1
print(bre)

Solution (Python):
import sys
n=int(input())
a=list(map(int,input().split()))
idx=0
if a==list(range(1,n+1)):
  print(0)
  sys.exit()
if sum(a)==n:
  print(n-1)
  sys.exit()
if 1 not in a:
  print('-1')
  sys.exit()
for i in range(1,n+1):
  for j in range(idx,n):
    if a[j]==i:
      idx=j
      break
    if j==n-1:
      print(n-i+1)
      sys.exit()

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

a = 0
c = 1

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

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

Solution (Python):
import sys

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

ans = 0
_find = 1
before = 0

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

for i in range(n):
    if a[i]==_find:
        ans += i-before
        _find += 1
        before = i+1

print(ans+n-before)

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

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

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
if 1 not in A:
    print(-1)
    exit()

target = 1
idx = 0
ans = 0
while idx < len(A):
    if A[idx] == target:
        target += 1
        ans += 1
    idx += 1
print(N - 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

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

Solution (Python):
from collections import deque
N=int(input())
A=map(int,input().split())

D=deque(A)
count = 1
for i in range(N):
    d = D.popleft()
    if d == count:
        count+=1
if count == 1:
    print(-1)
else:
    print(N-(count-1))

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

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
cnt = 0
key = 1
ans = False
for i,value in enumerate(A):
    if value == key:
        key += 1
        ans = True

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

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

ans = 0
count = 1
y = 0

if A.count(1) == 0:
    ans = -1
else:
    for i in range(n):
        if A[i] != count:
            ans += 1
            pass
        else: 
            count += 1

print(ans)

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

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


ans=bk
if counter-1==0:
  ans=-1
print(ans)

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

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

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

stt=0

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

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

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


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

Solution (Python):
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n = INT()
a = LIST()

i = 0
res = 0
count = 1
while i<n:
    if a[i] == count:
        count += 1
    i += 1
if count == 1:
    print(-1)
else:
    print(n-count+1)

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

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

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

Solution (Python):
x = int(input())
result = 0
ary = list(map(int,input().split()))
miss = False
res = 1
for i in range(x):
  if (res == ary[i]):
    res += 1
print(-1 if res-1 == 0 else x - res + 1)

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

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

print(ans)

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

Solution (Python):
from collections import defaultdict
import sys
import math
from datetime import datetime
import re
import math
def sol(N, S):

    radar = 1
    contigious = []
    for n in S:
        if n == radar:
            contigious.append(n)
            radar += 1
    if len(contigious) > 0:
        return len(S) - len(contigious)
    else:
        return '-1'







do_submit = True


def input_parse(input_str):
    lines = [x.strip() for x in input_str.split("\n") if x.strip()]
    parsed_lines = [list(map(str, line.split())) for line in lines]
    print(parsed_lines)
    
    
    S = parsed_lines[0][0]
    return S


if not do_submit:
    S = input_parse("""
    1905
    """)
    print(sol(S))

    S = input_parse("""
    0112
    """)
    print(sol(S))

    S = input_parse("""
    1700
    """)
    print(sol(S))

    S = input_parse("""
    0000
    """)
    print(sol(S))

    S = input_parse("""
    1001
    """)
    print(sol(S))



else:
    n = int(input())
    S = list(map(int, input().split()))
    
    print(sol(n, S))

Solution (Python):
n = int(input())
first = n
k = [int(x) for x in input().split()]
j = 1
for i in (k):
    if(i==j): j+=1
if(j==1): print("-1")
else: print(str(n-j+1))

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

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

flag=1
for i in range(0,N):
    if int(a[0][i])==flag:
        flag+=1
       
if flag==1:
    print(-1)
else:
    print(N-flag+1)

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

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

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

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

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

Solution (Python):
import fractions
y = int(input())
x = list(map(int, input().split()))
list=[0]

for i in range(len(x)):
  if x[i]== list[-1]+1:
    list.append(x[i])

if len(list)==1:
  print(-1)
else:
  print(len(x)-(len(list)-1))

Solution (Python):
test = ""

"""
1
1
"""
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
    

n = int(input2())
nums = list(map(int, input2().strip().split()))
nums.reverse()

ans = 0
wanted = 1
while nums:
    tmp = nums.pop()
    if tmp == wanted:
        wanted += 1
    else:
        ans += 1

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

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

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

if c != 0:
  print(N-len(b))
elif c == 0:
  print(-1)

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

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

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

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

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

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

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

Solution (Python):
N = int(input())
a = input().split(" ")

def search():
	
	search_start = 0
	for target in range(1, N+1):
		for j in range(search_start, N):
			if int(a[j]) == target:
				search_start = j + 1
				break
		else:
			
			
			if N != 1 and target == 1:
				return -1
			else:
				return N - (target - 1)
	else:
		
		
		return 0
	return False

print(search())

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

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

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

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

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

A = [a for i, a in enumerate(A) if a <= i+1]

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(map(int,input().split()))

cnt=1
flag=0
result=0

for item in a:
    if item ==cnt:
        flag=1
        cnt+=1
    else:
        result+=1

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

print(result)

Solution (Python):

n = int(input())


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

ans = 0

target = 1
has_ans = False
for i in range(0, n):
    if an[i] == target:
        has_ans = True
        target += 1
    else:
        ans += 1

print(ans if has_ans else "-1")

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

for i in range(N):
    if (a[i] == x):
        x += 1
        continue
    ans += 1


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

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

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

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

check = 1
ans = 0

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

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

Solution (Python):
n = int(input())
mx = 200000
mem = set()
a = list(map(int,input().split()))
num = [0 for _ in range(mx+1)]
for v in a:
    num[v]+=1
start = 1
idex = 0
while idex <n:
    if num[start]>0:
        while a[idex]!=start and idex<n:
            num[a[idex]] -=1
            idex+=1
        num[start]-=1
        idex+=1
        start+=1
    else:
        idex+=1
ans =(n-(start-1))
if ans <= n-1:
    print(ans)
else:
    print(-1)

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

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


def solve():
  if 1 not in arr:
    print(-1)
    return

  cnt = 1
  for i in range(0, n):
    if arr[i] == cnt:
      cnt += 1
  print(n - (cnt-1))

def main():
  solve()


if __name__ == "__main__":
  main()

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

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


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

    number_possible = 1

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

    return print(N - number_possible + 1)


solve()

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

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

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

Solution (Python):
def solve(n, a_list):
    search = 1
    for i in range(n):
        if a_list[i] == search:
            search += 1
    if search == 1:
        return -1
    else:
        return n - search + 1


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    res = solve(n, a_list)
    print(res)


def test():
    assert solve(3, [2, 1, 2]) == 1
    assert solve(3, [2, 2, 2]) == -1
    assert solve(10, [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]) == 7
    assert solve(1, [1]) == 0


if __name__ == "__main__":
    test()
    main()

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

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

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

count = 0
i = 0
d = 0
while i + d < len(a):
    if a[i + d] != i + 1:
        d += 1
        count += 1
    else:
        i += 1
if count < N:
    print(count)
else:
    print(-1)

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

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

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

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

ans = 0
block = 1
for i in li:
    if i == block:
        block += 1
    else:
        ans += 1
if len(li) == ans:
    ans = -1
print(ans)

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())
renga_list = [int(i) for i in input().split()]
now =1
count = 0
for i in renga_list:
    if i != now:
        count += 1
    else:
        now += 1
if now==1:
    print(-1)
else:
    print(count)

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

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

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

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

count = 0
ix = 1
for i in li:
  if i != ix:
    count += 1
  else:
    ix += 1

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

Solution (Python):
def solve():
    N, *a = map(int, open(0).read().split())
    
    if 1 not in a:
        print(-1)
        exit()
    
    ans = 0
    target = 1
    i_tmp = -1
    for i, x in enumerate(a):
        if x == target:
            ans += i - i_tmp - 1
            i_tmp = i
            target += 1
    ans += N - i_tmp - 1
    print(ans)


if __name__ == '__main__':
    solve()

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

bb = 0
left = 0

for i in range(n):
    j = 0
    for j in range(left, n):
        
        if la[j] == i+1:
            left = j + 1
            break
        else:
            bb += 1
    if j == n-1:
        break

if bb > n-1:
    print(-1)
else:
    print(bb)

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

num = 1
count = 0

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

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

Solution (Python):
def solve(lst):
    i = 1
    num_bricks = 0

    for num in lst:
        if num == i:
            num_bricks += 1
            i += 1
    
    if i == 1:
        return -1
    else:
        return len(lst) - num_bricks

N = input()
lst = list(map(int, input().strip().split(" ")))

print(solve(lst))

Solution (Python):
N = int(input())
alist = list(map(int, input().split()))
blist = []
alen = len(alist)

n = 0
i = 1

for a in alist:
    if a == i:
        i += 1
    else:
        blist.append(a)
        n += 1

if len(blist) == len(alist):
    print(-1)
else:
    print(n)

Solution (Python):
n=int(input())
la=input().split(" ")
l=[]
ans=0
c=1
for i in range(len(la)):
    l.append(int(la[i]))
for k in range(len(l)):
    if(l[k]==c):
        ans+=1
        c+=1

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

Solution (Python):

import sys
import bisect
N=input()
seq=map(int, sys.stdin.readline().split())

LIS = [seq[0]]
for i in range(len(seq)):
    if seq[i]>LIS[-1]:
        LIS.append(seq[i])
    else:
        LIS[bisect.bisect_left(LIS, seq[i])] = seq[i]

l=-1 
for i,x in enumerate(LIS):
    if i+1==x:
        l=x

if l==-1:
    print -1
else:
    print N-l

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


NextNum=1
Crash=0
for _ in range(n):
	
	if A[_]==NextNum:
		NextNum += 1
	else:
		Crash+=1

ans=-1
if NextNum>1:
	ans = Crash

print(ans)

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

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

ans += break_count

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

Solution (Python):


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

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

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



check_num = 1
K = 0
for i in range(N):
    if block_list[i] == check_num:
        K += 1
        check_num += 1

if K == 0:
    print(-1)    
else:
    print(len(block_list) - K)

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

criterion = 1
con = 0

L = []

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

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

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

start = 0
cnt = 0
for i in range(1, N+1):
  try:
    start = a.index(i, start)
  except:
    break
  else:
    cnt += 1

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

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
i = 1
TF = "F"
for j in range(N):
    if A[j] == i:
        i += 1
        TF = "T"
i -= 1
if TF == "T":
    print(N-i)
else:
    print(-1)

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
else:
    if cnt == 0:
        ans = -1
    else:
        ans = len(a)-cnt

print(ans)

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

r = 1
torf = False

for i in range(n):
  if r == int(a[i]):
    r += 1
    torf = True

if torf:
  print(len(a) - (r - 1))
else:
  print(-1)

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

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

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

print(ans)

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

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

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

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

Solution (Python):
n = int(input())
rec = -1
for ai_str in input().split():
    ai = int(ai_str)
    if rec == -1:
        if ai == 1:
            rec = 1
    else:
        if rec + 1 == ai:
            rec = ai
if rec == -1:
    print('-1')
else:
    print(n - rec)

Solution (Python):
import sys
N=int(input())
a = sys.stdin.readline().split()
i=1
for num in a:
    if int(num) == i:
        i=i+1
if i != 1:
    print(N-i+1)
else:
    print(-1)

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
now = 1
cnt = 0
flag = 2
if n == 1 and A[0] == 1:
    flag = 0
elif n == 1 and A[0] != 1:
    flag = 1
elif len(set(A)) == 1 and A[0] == 1:
    cnt = n -1
elif  len(set(A)) == 1 and A[0] != 1:
    flag = 1
elif 1 not in A:
    flag = 1
else:
    for a in A:
        if a == now:
            now += 1
        else:
            cnt += 1

if flag == 0:
    print(0)
elif flag == 1:
    print(-1)
else:
    print(cnt)

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

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

rengaList = input().split()
nowSearchRenga=1
cnt = 0
for i in range(renga):
  if int(rengaList[i]) == nowSearchRenga:
    nowSearchRenga=nowSearchRenga+1
    continue
  else:
    cnt=cnt+1
    
if i+1 == cnt:
  print(-1)
else:
  print(cnt)

Solution (Python):
import fractions
N = int(input())
A = list(map(int, input().split()))
find = 0
broken = 0

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

if find == 0:
  print(-1)
else:
  print(broken)

Solution (Python):
ans = 0

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

now = 1

for i in s:
    if i == now:
        now += 1
    else:
        ans += 1


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