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 sys
import math

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False


        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    n = [int(e) for e in lines[0].split(" ")][0]
    a = [int(e) for e in lines[1].split(" ")]

    return (n, a)

def solve(n, a):

    current_num = 1
    count = 0
    result = []
    for i in range(n):
        if a[i] != current_num:
            count = count + 1
        else:
            current_num = current_num + 1
            result.append(a[i])
    
    if debug:
        log("result=%s" % result)
        log("count=%s" % count)
    
    if result == []:
        count = -1

    for i in range(1, len(result) + 1):
        if result[i-1] != i:
            if debug:
                log("result[%d]=%s" % (i, result[i-1]))
            count = -1
            break


    return count

def main():
    
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r)
    else:
        print("%s" % result)

if __name__ == '__main__':

    main()

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

c = 1
for i, v in enumerate(a):
    if v == c:
        c += 1

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

Solution (Python):



def main():
    num = int(input())
    origin = [int(i) for i in input().split(" ")]
    break_count = 0
    want = 1
    satisfy = False
    for b in origin:
        if b == want:
            want += 1
            satisfy = True
            continue
        else:
            break_count += 1
    print("-1" if not satisfy else break_count)


if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
number=input().split(' ')
number_list=[]
for i in number:
    number_list.append(int(i))
index=1
flag=0
count=0
for i in number_list:
    if(i==1 and flag==0):
        flag=1
        index+=1
    elif (i==index):
        index+=1
    else:
        count+=1

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

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




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

Solution (Python):
num, bricks = int(input()), list(map(int,input().split(" ")))
count = 1
smash = 0
for x in bricks:
    if count == x: count += 1
    else: smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)

Solution (Python):
a=int(input())
q=[]
q+=[int(x) for x in input().split()]
s=q.count(1)
r=1
e=0
if s==0:
  print("-1")
else:
  for i in range(a):
    if r==q[i]:
      r+=1
  print(a-r+1)

Solution (Python):
num, bricks, count, smash = int(input()), [int(x) for x in input().split(" ")], 1, 0
for x in bricks:
    if count == x: count += 1
    else: smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)

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

Solution (Python):
from __future__ import print_function

import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

















































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

    cnt=0
    j=1
    for i in range(n):
        if l[i]==j:
            j+=1
            cnt+=1
            pass
        else:
            pass
    if cnt==0:
        print(-1)
    else:
        print(n-cnt)
    return

if __name__ == '__main__':
    main()

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

count = 0
tmpNumber = 1

for idx in range(N):
    if (a[idx] != tmpNumber):
      	count += 1
    else:
        tmpNumber += 1
if (tmpNumber == 1):
    print(-1)
else:
    print(count)

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

count = 0
value = 1
for i in range(0, len(array)):
    if (value == array[i]):
        value += 1
    elif (value != array[i]):
        count += 1

if (value == 1):
    print(-1)
    exit()
print(count)

Solution (Python):
import numpy as np
N = int(input())
a_array = list(map(int,input().split()))

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

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

i = 0

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

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

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

num = 0
j = 1

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

print(num)

Solution (Python):
N = int(input())
Input = input().split()

Inputint = [int(i) for i in Input]

new = []
COUNTER = 1
for i in Inputint:
    if COUNTER == 1:
        if i == 1:
            new.append(i)
            COUNTER += 1
    else:
        if i == new[-1]+1:
            new.append(i)
        else:
            continue

if not new:
    print(-1)
else:
    print(N-len(new))

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

counter = 0
breaknum = 0

flag = False

for i in list(aList):
    if(i == counter+1):
        counter += 1
    else:
        breaknum += 1
    
if(counter == 0):
    print(-1)
else:
    print(breaknum)

Solution (Python):
num, bricks, count, smash = int(input()), [int(x) for x in input().split(" ")], 1, 0
for x in bricks:
    if count == x: count += 1
    else: smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
b = 1
anc = 0
roop = 0
if 1 in a:
    for i,v in enumerate(a):
        if v == b:
            anc += roop
            temp = i
            b+=1
            
            roop = 0
            
            
            

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

    print(-1)

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

is_over = False
now = 0

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

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

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

dp = [0]*N

if a[0] == 1:
    dp[0] = 1

for i in range(N-1):

    if a[i+1] == dp[i] + 1:
        dp[i+1] = dp[i] + 1
    else:
        dp[i+1] = dp[i]


ans = N - dp[-1]
if ans > N -1:
    print "-1"
else:
    print ans

Solution (Python):
num, bricks, count, smash = int(input()), [int(x) for x in input().split(" ")], 1, 0
for x in bricks:
    if count == x: count += 1
    else: smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)

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

def cal(i):
    c = 1
    ans = 0
    for j in range(n):
        if i[j] == c:
            c += 1
        else:
            ans += 1

    if c == 1:
        return -1
    else:
        return ans

print(cal(i))

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




idx = 0
cnt = 0
num = 1
brick = 0
flg = False
while True:
    if num == A[idx]:
        flg = True
        num += 1
        brick += cnt
        cnt = 0
    else:
        cnt += 1
    idx += 1
    if idx > N - 1:
        brick += cnt
        break

if flg == False:
    brick = -1

print(brick)

Solution (Python):

from collections import deque
n = int(input())
a = deque(list(map(int,input().split())))
ans = 0
count = 1
i = 0
while True:
    if a[i] != count:
        ans += 1
        a.popleft()
    else:
        count += 1
        i += 1
    if n == ans + i:
        break
if len(a) == 0:
    print(-1)
else:
    print(ans)

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

x = 1
b = 0
for i in a:
    if i != x:
        b += 1
    elif i == x:
        x += 1

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

Solution (Python):

n = int(input())
a =[int(i) for i in input().split()]
j = 1
ans = 0
k =0
l = -1
if 1 not in a:
	ans = -1
else:
		for i in range(k,n):
			if k>=n:
				break
			elif a[i] == j:
				ans+=i-k
				k = i+1
				j +=1
				l = i

if l!=-1:
	ans+=n-1-l
print(ans)
"""
k  =1
j =0
for  i in range(k,10):
		if i !=2:
			print(i)
		else:
			k = 3
			break
		j +=1
"""

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,*A = map(int,read().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())
num_list = [int(i) for i in input().split()]

count = 0
match = 1

for i in range(N):
    if num_list[i] == match:
        match += 1
    else:
        count += 1

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

Solution (Python):
N, *L,  = [list(map(int, s.split())) for s in open(0)]
L = L[0]
minj = 0
for l in L:
    if l == minj + 1:
        minj = l
if minj == 0:
    print(-1)
else:
    print(len(L) - minj)

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    n = int(input()[:-1])
    l = list(map(int, input()[:-1].split(" ")))

    c = 1
    s = 0
    tmp = 0
    while l:
        if tmp >= n:
            break
        if l[tmp] != c :
            s += 1
        else:
            c += 1
        tmp += 1

    res = s
    if s == n:
        res = -1

    print(res)

main()

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

cnt = 0
n = 1

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

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

print(cnt)

Solution (Python):
num, bricks, count, smash = int(input()), [int(x) for x in input().split(" ")], 1, 0
for x in bricks:
    if count == x: count += 1
    else: smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)

Solution (Python):

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

def counter(a):
    count = 0
    i = 1
    for row in a:
        if row != i:
            count = count + 1
            i = i
        else:
            count  = count
            i = i + 1
    return count

if 1 in a:
    print(counter(a))
else:
    print('-1')

Solution (Python):
import sys

length = int(input())
bricks = input().split(' ')

counter = 0
top = 0
for i, brick in enumerate(bricks):
    if top+1 == int(brick):
        top += 1
    else:
        counter += 1
if top == 0:
    counter = -1
print(counter)

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

ans = 0
by = 1

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

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

if ans == n:
  print(-1)
elif ans == 0 and a == n+1:
  print(0)
else:
  print(ans)

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

ans = 0
for i in range(n):
    for j in range(i + ans, n):
        if renga[j] != i + 1:
            ans += 1
            continue
        break

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

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

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

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

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

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


myans = 0
mynum = 1

i = 0 
while i < N:
    
    if mylist[i] == mynum:
        mynum += 1
        
    else:
        myans += 1
        
    i += 1

if myans != N:
    print(myans)
else:
    print(-1)

Solution (Python):
N = int(input())
A = map(int, input().split())
B = []
cnt = 0

for a in A:
    if a == len(B)+1:
        B.append(a)
    else:
        cnt += 1

if len(B) != 0 and B[-1] == N-cnt:
    print(cnt)
else:
    print(-1)

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

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

pos_cnt = 1
remove_cnt = 0
for d in data:
    if d == pos_cnt:
        pos_cnt += 1
    else:
        remove_cnt += 1

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

Solution (Python):
import sys

n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
cnt=0
i=1
for a in A:
    if a ==i:
        i+=1
 
ans =n-i+1
if ans ==n:
    print(-1)
else:
    print(ans)

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

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

i = 0
c = 0
n = 1

while True:
    if i >= N:
        break
    while i < N and a[i] != n:
        c += 1
        i += 1
    if c == N:
        c = -1
        break
    i += 1
    n += 1

print(c)

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

j=1
ans=0
tmp=0
for i in range(0,N):
  if a[i]==j:
    ans += i-tmp
    tmp = i+1
    j += 1


if ans==0 and tmp==N:
  print(ans)
elif ans==0 and j==1:
  print(-1)
elif N>tmp:
  print(ans+(N-tmp))
else:
  print(ans)

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

if not(1 in A):
  print('-1')
else:
  index = 0
  count = 1
  while index<N:
    if A[index] == count:
      count+=1
    index+=1
  print(N-(count-1))

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

count = 0
if 1 in x:
    try:
        j = 0
        for i in range(n):
            while x[j]!=(i+1):
                j = j+1
                count += 1    
            j +=1        
        print(count)
    except:
        print(count)
else:
    print(-1)

Solution (Python):
import sys

if sys.platform =='ios':
	sys.stdin=open('input_file.txt')
	

import fractions

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

Solution (Python):

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


i = 1

for renga in renga_list:
    if i == renga:
        i += 1
        
result = n - i + 1
if n == result:
    print(-1)
else:
    print(result)

Solution (Python):
n = int(input())
s = list(map(int,input().split()))
c = 0
l = []
ind = 1

for i in s:
  
  if i == ind:
    ind += 1
    
  else:
    c += 1

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

Solution (Python):
def main():
	n = int(input())
	
	a = list(map(int,input().split()))
	
	
	ans = 0
	kijun=1
	check = 0

	while check < n:
		
		
		if a[check] == kijun:
			check += 1
			kijun += 1
			
		else:
			check += 1
			ans += 1
		
		



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




if __name__ == '__main__':
	main()

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

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

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

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

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

Solution (Python):
num, bricks, count, smash = int(input()), [int(x) for x in input().split(" ")], 1, 0
for x in bricks:
    if count == x: count += 1
    else: smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)

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

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

Solution (Python):
num, bricks, count, smash = int(input()), [int(x) for x in input().split(" ")], 1, 0
for x in bricks:
    if count == x: count += 1
    else: smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)

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

r = 0
i = 1
k = 0
while True:
    if a[k] == i:
        i += 1
        k += 1
    else:
        k += 1
        r += 1
    if k >= len(a):
        if r == len(a):
            print(-1)
        else:
            print(r)
        exit()

Solution (Python):
num, bricks, count, smash = int(input()), [int(x) for x in input().split(" ")], 1, 0
for x in bricks:
    if count == x: count += 1
    else: smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)

Solution (Python):
num, bricks, count, smash = int(input()), [int(x) for x in input().split(" ")], 1, 0
for x in bricks:
    if count == x: count += 1
    else: smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)

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

Solution (Python):
num, bricks, count, smash = int(input()), [int(x) for x in input().split(" ")], 1, 0
for x in bricks:
    if count == x: count += 1
    else: smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)

Solution (Python):

N=int(input())
mylist=list(map(int, input().split()))
i=1
j=0
count=0

while j<N:
    if mylist[j]==i:
        count+=1
        i+=1
        j+=1
        
    else:
        j+=1
        

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
cnt = 0
k = 0
for i in range(1, n + 1):
    try:
        while i != a[k]:
            cnt += 1
            k += 1
    except IndexError:
        break
    k += 1

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

Solution (Python):
N = int(input())
block = list(map(int, input().split()))
num = 1
times = 0
j = 0
while j < N:
  if block[j] != num:
    times += 1
  else:
    num += 1
  j += 1
if num != 1:
  print(times)
else:
  print("-1")

Solution (Python):
import numpy as np

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

    leap_seq = [0]
    for n in range(N):
        if leap_seq[-1]+1 == As[n]:
            leap_seq.append(As[n])

    del leap_seq[0]
    if len(leap_seq) == 0:
        print(-1)
    else:      
      print(int(N-len(leap_seq)))

if __name__ == "__main__":
    main()

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

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


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

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

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

for i in range(1, n+1):
  for j in range(b, n):
    if i == a[j]:
      out += j-b
      b = j+1
      break
  else:
    out += n-b
    break

if out == n:
  out = -1

print(out)

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

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

    else:
        flag+=1

if 1 not in A:
    print(-1)
else:
    print(flag)

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

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

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

Solution (Python):
import sys
bbn=1000000007
	

		
def main():
	n = int(input())
	al = list(map(int, input().split()))
	
	if 1 not in al:
		return -1
		
	cv = 1
	bn=0
	for v in al:
		if v == cv:
			cv += 1
		else:
			bn += 1
		
	print(bn)
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

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

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

search = 1
ans = 0


for i in range(len(l)):
  if not l[i] == search:
    ans += 1
  else:
    search += 1

if ans == len(l):
  ans = -1

print(ans)

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

purged_data = [] 
tmp = a[0] - 1
s=1
for i, e in enumerate(a):
    if e==s:
        purged_data.append(e)
        tmp = e
        s+=1
for i in range(len(purged_data)):
    if purged_data[i]!=i+1:
        print(-1)
        sys.exit()
if len(purged_data)==0:
    print(-1)
    sys.exit()
print(len(a)-len(purged_data))

Solution (Python):
a = int(input())
array = list(map(int, input().strip().split()))
brk = 0
ok = 0
su = 1
for i in array:
    if su == i:
      ok += 1
      su += 1
    else:
      brk +=1
if brk == 0 and ok != 0:
  print(0)
elif ok == 0:
  print(-1)
else:
  print (brk)

Solution (Python):
import unittest


class TestD(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([2, 1, 2]), 1)

    def test_2(self):
        self.assertEqual(think([2, 2, 2]), -1)

    def test_3(self):
        self.assertEqual(think([3, 1, 4, 1, 5, 9, 2, 6, 5, 3]), 7)


def solve():
    a = read()
    result = think(a)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return read_type(int, n)


def read_float(n):
    return read_type(float, n)


def read_type(t, n):
    return list(map(lambda x: t(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a):
    if 1 not in a:
        return -1
    next_index = 1
    count = 0

    for i in a:
        if next_index == i:
            next_index += 1
        else:
            count += 1
    return count


def write(result):
    print(result)


if __name__ == '__main__':
    
    solve()

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

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

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

Solution (Python):

N = int(input())


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

idx = 1
for i in range(len(datas)):	
    if datas[i] == idx:
        idx += 1



if idx - 1 == 0:
    print(-1)
else:
    print(len(datas) - (idx-1))

Solution (Python):
N = int(input())
raw_str = input().split()
temp = 1
breaked = 0

for i in raw_str:
    if int(i) > temp or int(i) < temp:
       breaked += 1
    else:
        temp += 1
        continue

if(breaked == N):
    if(raw_str[0] == '1'):
        print(0)
    else:
        print(-1)
else:
    print(breaked)

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

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

t=[]
d=0
for i in s:
  if i==d+1:
    d=i

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

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


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

    print(N-c)

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

cur=1
cnt=0
for x in xs:
    if x == cur:
        cnt += 1
        cur += 1

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

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

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

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

N = input().split(' ')

count = 1

output = 0

for i in range(len):
  num = int(N[i])
  if num == count:
    count+=1
  else:
    output+=1
   
if count == 1:
  output = -1
  
print(output)

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

counter=0
start = 0
end = N

for i in range(N):
    try:
        index = NL.index(i+1, start, end)
        start = index+1
    except:
        break
    else:
        counter += 1


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

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

base = 1
l = []
for x in As:
    if x == base:
        l.append(x)
        base += 1

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

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

if len(a) - len(data) == len(a):
  print('-1')
else:
  print(len(a) - len(data))

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

ans = 0
current = 1

if n == 1 and a[0] == 1:
    print('0')
else:
    for i in range(n):
        if current != a[i]:
            ans += 1
        elif current-1 == a[i]:
            ans += 1
        else:
            current += 1

    if current != 1:
        print(ans)
    else:
        print('-1')

Solution (Python):
d = int(input())
nums = list(map(int, input().split(' ')))

crashed = []
i = 1
output = -1


if len(nums) == 1:
  if nums[0] == 1:
    output = 0
  print(output)

else:
  crash_count = 0
  for n in nums:
    if n == i:
      crashed.append(n)
      i += 1
    else:
      crash_count += 1
  success = True
  pre = 0
  if len(crashed) == 0:
    print(-1)
  else:
    for n in crashed:
      if n == pre + 1:
        pre = n
      else:
        success = False
        break
    if success:
      print(crash_count)
    else:
      print(-1)

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

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

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

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

Solution (Python):
import sys

len = int(input())
input_str_arr = input().split(" ")
input = [int(n) for n in input_str_arr]


base = 1
count = 0

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

for i in range(len):
    if(base == input[i]):
        base+=1
        continue
    count+=1

print(count)

Solution (Python):
def main(n: int, a: list):
    ans = 0

    i = 1

    if 1 not in set(a):
        print(-1)
        return

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

    print(ans)


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))

    main(n, a)

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

num = 1
counter = 0

for n in range(N):
    if S[n] == num:
        num += 1
    else:
        counter += 1

if(N == counter):
    counter = -1

print(counter)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()] 
C = 1
D = 0
for i in range(N):
	if A[i] != C:
		D += 1
	else:
		C += 1
if D==N:
	print(-1)
else:
	print(D)

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


kari = int(1)
an = 0


for i in range(N):
    if n[i] == kari:
        kari = kari +1
        
       


an = 1 + N-kari


if min(n) > 1.5 :
    ANS = -1
else:
    ANS = an

print(ANS)

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

check_num = 1
delete_num = 0
for i in input().split():
  i = int(i)
  if i == check_num:
    check_num += 1
  else:
    delete_num += 1

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

Solution (Python):
N = int(input())
seq = list(map(int, input().split()))
best = float('inf')
if 1 in seq:
    best = N - 1
else:
    print(-1)
    quit()

cur = 1
todel = 0
for i in range(N):
    if seq[i] == cur:
        cur += 1
    else:
        todel += 1
best = min(best, todel)

print(best)

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

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

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

if(j!=1):
    print(n-j+1)
else:
    print(-1)

Solution (Python):
import numpy as np
N = int(input())
li = list(map(int, input().split()))

list = list(np.arange(1, N+1))
check = 1
for i in range(N):
    if li[i] == check:
        check += 1

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

Solution (Python):


n = int(input())
a_list = list(map(int, input().split(' ')))
result = []

c = 0
for i in range(1, n+1):
    for j in range(c, n):
        if i == a_list[j]:
            result.append(i)
            c = j
            break
    if len(result) != i:
        break

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