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())
nums = [int(x) for x in input().split()]

dp = [float('inf')] * N
rest = [0] * N
if nums[0] == 1:
    dp[0] = 0
    rest[0] = 1
else:
    dp[0] = 1
    rest[0] = 0

for i, num in enumerate(nums[1:], start=1):
    if rest[i - 1] + 1 == num:
        dp[i] = dp[i - 1]
        rest[i] = rest[i - 1] + 1
    else:
        dp[i] = dp[i - 1] + 1
        rest[i] = rest[i - 1]

if dp[-1] == N:
    print(-1)
else:
    print(dp[-1])

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

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

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

else:
    print(-1)

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

flag = 0
cnt = 0
for i in numbers:
    if i == flag + 1:
        flag = i
    else :
       cnt += 1 

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

Solution (Python):
import sys

str = sys.stdin.readlines()

n = int(str[0])
alist_str = str[1].split()

target = 1
breaks = 0
for a in alist_str:
    if int(a) == target:
        target += 1
    else:
        breaks += 1

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

Solution (Python):
import sys

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

ans = 0
s = 1

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

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

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

standard = 1
counter = 0

for item in List:
  if item != standard:
    counter +=1
  else:
    standard +=1

if standard ==1:
  print(-1)
else:
  print(counter)

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

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

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

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

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

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
c = 0
b = 1
if 1 not in A:
    print(-1)
    exit()
for i in A:
    c += 1
    if i == b:
        b += 1
        c -= 1
print(c)

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

Solution (Python):
import math

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

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

Solution (Python):


def resolve():
    N = int(input().rstrip())
    a = list(map(int, input().rstrip().split(" ")))

    k = 0
    m = 1
    for x in a:
        if x == m:
            m += 1
            continue
        k += 1
    if len(a) == k:
        k = -1
    print(k)

if __name__ == "__main__":
    resolve()

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

j = 1
count = 0

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

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

cnt = 0
sign = 1

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

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

Solution (Python):
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import fractions
from functools import reduce
from operator import mul
import bisect
import sys
import logging
import heapq
import itertools

logging.basicConfig(level=logging.ERROR)

input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	n = int(input())
	a = list(map(int,input().split()))
	if(1 not in a):
		print(-1)
		return
	c = 1
	for i in a:
		if(i==c):
			c+=1
	print(n-c+1)

def factorization(n):
	if n<2:
		return []
	arr = []
	temp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if temp%i==0:
			cnt=0
			while temp%i==0:
				cnt+=1
				temp //= i
			arr.append([i, cnt])

	if temp!=1:
		arr.append([temp, 1])

	if arr==[]:
		arr.append([n, 1])

	return arr

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(numbers):
	return reduce(math.gcd, numbers)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

class PriorityQueue():
	def __init__(self):
		self.queue = []
	def push(self,i):
		heapq.heappush(self.queue,-i)
	def pop(self):
		return -1 * heapq.heappop(self.queue)
	def sum(self):
		return -sum(self.queue)

main()

Solution (Python):
N=int(raw_input())
A=[0 for i in range(N)]
s = raw_input().split()
for i in range(N):
    A[i] = int(s[i])



p = 0
n = 0
while (p < N):
    if A[p] == n+1:
        n = n+1
    p += 1

if n==0:
    print -1
else:
    print N-n

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

    count = 0
    pointer = 1
    for a_i in a:
        if a_i == pointer:
            pointer += 1
        else:
            count += 1

    if count == N:
        count = -1

    print(count)
        

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
data = list(map(int, input().split()))
now = 1
result = 0

if data.count(1):
    for i in range(n):
        if data[i] != now:
            result += 1
        else:
            now += 1
    print(result)
else:
    print(-1)

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

count=1
result=0

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

for i in range(len(li)):
  if(li[i]==count):
    count+=1
  else:
    result+=1
print(result)

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

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

counter = 0
for i in range(N):
    if (int(num[i]) == counter + 1):
        counter += 1

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

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

S = {0}

for i, v in enumerate(A):
    S2 = set()
    for j in S:
        if v == i - j:
            S2.add(j)
        else:
            S2.add(j + 1)
    S = S2

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

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
check = True
ans = True
i = 0
j = 0
count = 0
while check:
    if a[j]==i+1:
        i += 1
        count = i
    j += 1
    if j==n:
        check = False

if count!=0:
    print(n-i)
else:
    print("-1")

Solution (Python):

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


if 1 not in a:
    print('-1')
    exit()
else:
    num = 1
    for i in a:
        if i == num:
            brick.append(i)
            num += 1

print(n-len(brick))

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

Str = input().split(" ")

NumList = [int(s) for s in Str]

Count = 0
Break = 1
for i in range(len(NumList)):
  if Break == NumList[i]:
    Break += 1
  else:
    Count += 1

if Count == Num:
  print("-1")
else:
  print(Count)

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



k=0
i=0
while n >i:
  if A[i] ==k+1:
    k +=1
  i +=1
if k==0:
  print(int(-1))
else:
  print(n-k)

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

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

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

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

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

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

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

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
def isPossible(n):
    cnt = 1
    for a in A:
        cnt += (cnt == a)
    return n < cnt

if (1 not in A):
    print(-1)
else:
    lb = 0
    ub = 200100
    for i in range(25):
        if (ub-lb == 1): break
        mid = (lb + ub) // 2
        if isPossible(mid):
            lb = mid
        else:
            ub = mid
    print(N-lb)

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

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

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

i = 0
pointer = 1
cnt = 0
while i < N:
    if a[i] == pointer:
        pointer += 1
        cnt += 1
    i += 1

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

Solution (Python):
import collections
import math
import operator as op
from functools import reduce
import numpy as np
import math
import bisect


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


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

    a_pos = []
    n_breaks = 0
    i = 1
    for ai in a:
        if i - ai < 0:
            n_breaks += 1
        else:
            a_pos.append(ai)
            i += 1

    

    
    if len(a_pos) == 0 or a_pos[0] != 1:
        print(-1)
    else:
        i = 1
        for ai in a_pos:
            if i - ai != 0:
                n_breaks += 1
            else:
                
                i += 1
        print(n_breaks)


if __name__ == '__main__':
    main()

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

count=0
req = 1
if 1 not in a:
    print(-1)
else:
    for i in a:
        if i==req:
            req+=1
        else:
            count+=1
    print(count)

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


    if len(A) == 1 and A[0] == 1:
        print(0)
        exit()

    set_A = set(A)
    set_B = set()
    t = 1
    for i in range(1, len(A)):
        if not i in set_A:
            break
        if i in set_B:
            continue
        set_B.add(i)
        t += 1
    if t == 1:
        print(-1)
        exit()

    ans = 0
    tt = 1
    for a in A:
        if a == tt:
            tt += 1
            ans += 1
        else:
            pass

    print(len(A)-ans)

if __name__ == '__main__':
    main()

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

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

count = 1

if 1 in a:
  ind = a.index(1)
  
  for i in range(ind,n):
    if a[i] == count+1:
      count += 1

  print(len(a) - count)
else:
  print(-1)

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

Solution (Python):







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

k = 1

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

ans = N - k + 1

if ans == N:
    ans = -1

print(ans)

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

C=1
M=0

for n in range(N):
  if int(A[n])!=C:
    M+=1
  else:
    C+=1
    
if M==N:
  M=-1

print(M)

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

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

if count == 1:
    print(-1)

else:
    print(ans)

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

cc = 1  
nuke_count = 0 

for a in A:
    if a == cc:
        cc += 1
    else:
        nuke_count += 1
        
if nuke_count == N:
    print('-1')
else:
    print(nuke_count)

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

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

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

c = 0
r = []
num = 1

for i in range(n):
    if a[i] == num:
        r.append(a[i])
        num += 1
    else:
        c +=1

if r == []:
    print(-1)
else:
    print(c)

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

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

num = 1
break_cnt = 0

for i in a:
    if i == num:
        num += 1
    else:
        break_cnt += 1
if n == break_cnt:
    print(-1)
else:
    print(break_cnt)

Solution (Python):



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


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

print(c if a > 1 else -1)

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

s=1
for i in range(len(X)):
    if X[i]==s:
        s+=1

if s==1:
    print(-1)
else:
    print(len(X)-(s-1))

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

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

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

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

if count_break == n :
    print('-1')
else:
    print(count_break)

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

now = 1
count = 0

for i in a:
  if i == now:
    now += 1
  else:
    count += 1
if now != 1:
  print(count)
else:
  print(-1)

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

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


c = min(L)
flag = False
if  c == 1:
    flag = True

li = []
for i in range(n):
    if L[i] == c and flag == True:
        li.append(c)
        c = L[i]+1

if flag:
    print(len(L)-len(li))
else:
    print(-1)

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

Solution (Python):
import sys

read = sys.stdin.read
N, *a = map(int, read().split())
a = [0] + a

seq = []
idx = 1
for i in range(1, N + 1):
    if a[i] == idx:
        seq.append(idx)
        idx += 1

if seq:
    print(N - len(seq))
else:
    print(-1)

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

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

if 1 not in a:
  print(-1)
else:
  
  break_num = 0  
  before = 0  
  search = 1  
  
  for i in range(N):
    if search == a[i]:
      
      break_num += (i - before) - 1
      before = i
      search += 1

  break_num += (N - before)
  print(break_num)

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

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

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

flg = False
ret = 0
i = 1
for tmp in a:
    if(i != tmp):
        ret += 1
    else:
        i += 1
        flg = True

if not flg:
    print(-1)
else:
    print(ret)

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

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

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

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

now=1
to_break=0
ans=False

for item in a:
  if item==now:
    now+=1
    ans=True
    
  else:
    to_break+=1
    
    
if ans:
  print(to_break)
else:
  print(-1)

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

k = 0

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

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

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

ans = 0
n = 0

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

Solution (Python):

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

ans = -1
subst = 0
nxtid = 1
for i in range(n):
    if a[i] == nxtid:
        subst += 1
        nxtid += 1
if subst > 0:
    ans = n - subst
print(ans)

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

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

count = 0
now = 1

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

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

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

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

p = 1
ret = 0
ok = False

for x in a:
    if x != p:
        ret += 1
    else:
        p += 1
        ok = True
print(ret if ok else -1)

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

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

Solution (Python):
N = int(input())
B = list(map(int, input().split()))
cur = 0
for a in B:
    if a == cur + 1:
        cur = a

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

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
check = [0]*n
count = 1
sum = 0
back = 0
for i in range(n):
  if l[i] == count:
    check[i] = 1
    count += 1
  
    
if check.count(1) == 0:
  print(-1)
elif check.count(1) == n:
  print(0)
else:
  print(check.count(0))

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

target = 1
for i in range(n):
    if a_list[i] == target:
        target += 1

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

Solution (Python):

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

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

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

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

Solution (Python):


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

b = []
count = 1
del_x = 0
for i in range(0, n):
    if a[i] == count:
        count += 1
    else:
        del_x += 1

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

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

pos = 1
ans = 0
leng = len(alist)
while(leng >= pos+ans):
    if (pos != alist[pos-1+ans]):
        ans += 1
    else:
        pos += 1

if (leng == ans):
    print("-1")
else:  
    print (ans)

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

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

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

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



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

Solution (Python):
from sys import stdin
f_i = stdin

N = int(f_i.readline())

a = list(map(int, f_i.readline().split()))

ans = N
idx = 0
num = 1

while True:
    try:
        idx = a.index(num, idx)
        ans -= 1
        num += 1
    except ValueError:
        break

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

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


count = 1
nocount = 0
for i in a:
  if i == count:
    count += 1
  else:
    nocount += 1 
    
    

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

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

Solution (Python):

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


if __name__ == "__main__":
    main()

Solution (Python):

import math
import datetime
import itertools
import sys
import copy





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





index = 1
cnt = 0
for i in range(N) :
  if L[i] == index :
    index += 1
    cnt += 1

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

Solution (Python):

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

a_index = -1
ans = 0
for i in range(1, N + 1):
    for j in range(a_index + 1, N):
        if a_list[j] == i:
            a_index = j
            break
        else:
            ans += 1
    if j == N - 1:
        break
if ans == N:
    print(-1)
else:
    print(ans)

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

counter = 0
idx = 1

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

    print(counter)

elif N == 0:
    if a[0] == 1:
        print(0)
else:
    print(-1)

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

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

    else:
        ans += cnt
        cnt = 0
        num += 1

ans += cnt
if 1 not in a:
    print(-1)
else:
    print(ans)

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

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

cnt = 1
ret = 0

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

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

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

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

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

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

Solution (Python):
from collections import deque
n = int(input())
l = deque(list(map(int, input().split())))
now = 1
ans = 0

for _ in range(n):
  if l.popleft() == now:
    now += 1
  else:
    ans += 1
  
print(-1 if ans == n else ans)

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

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

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

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

    else:
        count += 1

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

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

num=1
cnt=0
for i in l:
  if i==num:
    num+=1
  else:
    cnt+=1    
 
if cnt!=n and n-cnt==num-1:
  print(cnt)
else:
  print(-1)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
s=1
i=0
while i<N:
  if s==A[i]:
    s+=1
  i+=1
mi=N-(s-1)
if 1 not in A:
  print(-1)
else:
  print(mi)

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

Solution (Python):
import numpy as np
n=int(input())
a=input().split()
a=np.array(a,dtype='int32')
k=0
x=0
for i in range(n):
	if a[i]==x+1:
		x+=1
	else:
		k+=1
if k>=n:
	print('-1')
else:
	print(k)

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

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

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
add,point,cnt,flag=0,1,0,0
while add!=n:
    if A[add]==point:
        point +=1
        flag=1
    else:
        cnt +=1
    add +=1
print(cnt if flag==1 else -1)

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

i = 0
cnt = 0

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

    print(cnt)
else:
    print(-1)

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

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

current = 1
for _a in a:
    if current == _a:
        current += 1

current -= 1
if current == 0:
    print(-1)
else:
    print(n-current if n-current > 0 else 0)

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

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

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

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

present_num = 0


for brick in bricks:
    if brick == present_num + 1:
        present_num += 1

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

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