Problem:
 Score : 400 points    Problem Statement We have N bricks arranged in a row from left to right.  The i -th brick from the left (1 \leq i \leq N) has an integer a_i written on it.  Among them, you can break at most N-1 bricks of your choice.  Let us say there are K bricks remaining. Snuke will be satisfied if, for each integer i  (1 \leq i \leq K) , the i -th of those brick from the left has the integer i written on it.  Find the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.      Constraints  All values in input are integers.  1 \leq N \leq 200000  1 \leq a_i \leq N         Input Input is given from Standard Input in the following format:  N  a_1  a_2  ...  a_N       Output Print the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.        Sample Input 1 3
2 1 2      Sample Output 1 1  If we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.       Sample Input 2 3
2 2 2      Sample Output 2 -1  In this case, there is no way to break some of the bricks to satisfy Snuke's desire.       Sample Input 3 10
3 1 4 1 5 9 2 6 5 3      Sample Output 3 7       Sample Input 4 1
1      Sample Output 4 0  There may be no need to break the bricks at all.

Solution (Python):
import math
from math import ceil
from math import factorial
from collections import Counter
from operator import itemgetter
import bisect
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())
def gcd(a,b):
	if(b==0):
		return a
	return gcd(b,a%b)

n = ii()
a = iia()
x = 1
c = 0
for i in a:
	if(x==i):
		x+=1
	else:
		c+=1
if(c==n):
	c=-1
print(c)

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

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

Solution (Python):
def inp():
 return [int(x) for x in input().split()]

N = int(input())
a = inp()

n = 1
i = 0 

k = 0

while i<N:
  while i<N and a[i]!=n:
    i+=1
    k+=1
  i+=1
  n+=1

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

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

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

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

ans = 0

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

Solution (Python):

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

Solution (Python):
def solve(n, a):
    t = 1
    for x in a:
        if x == t:
            t += 1
    return -1 if t == 1 else n + 1 - t

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

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

f=0
g=1
for i in range(0,n):
    if A[i]!=g:
        f+=1
    else:
        g+=1

if g!=1:
    print(f)
else:
    print(-1)

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

cnt = 0
num = 1
for i in range(len(li)):
    if li[i] != num:
        cnt += 1
    else:
        num += 1

if len(li) != cnt:
    print(cnt)
else:
    print(int(-1))

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

cnt = 0
num = 1
for i in range(len(li)):
    if li[i] != num:
        cnt += 1
    else:
        num += 1

if len(li) != cnt:
    print(cnt)
else:
    print(int(-1))

Solution (Python):
from collections import deque

N = int(input())
li = deque(list(map(int, input().split())))

ans = N
num = 1
for i in range(N):
  ind = li.popleft()
  if ind == num:
    ans -= 1
    num += 1
    
if N == ans : ans = -1

print(ans)

Solution (Python):
N = input()
num_list = input().split()

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

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

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

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

cnt = 0
cur = 1

for i in nums:
    if i == cur:
        cur+=1
    else:
        cnt+=1
if cur == 1:
    print(-1)
else:
    print(cnt)

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

index = 1
bre = 0
for a in As:
	if index == a:
		index += 1
	else:
		bre += 1
else:
	if N != bre:
		print(bre)
	else:
		print("-1")

Solution (Python):
n = int(input())
z = input().split(" ")

look_for = 1
breaks = 0

for i in z:
    if int(i) == int(look_for):
        look_for += 1
        continue
    breaks += 1

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

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

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

ColNum = 1
ans = 0
for i in range(N):
  if(As[i] != ColNum):
    ans += 1
  else:
    ColNum += 1

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

print(ans)

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

A = [n for n in map(int, raw_input().split())]
    
st = 1
num_brk = 0

for a in A:
    if a == st:
        st += 1
    else:
        num_brk += 1

if num_brk == N and st == 1:
    print '-1'
else:
    print '{}'.format(num_brk)

Solution (Python):
N = int(input())
S = input().split()
a = list(map(int,S))
count = 1
broken = 0
flag = False

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

if flag :
  print(N - broken)
else :
  print(-1)

Solution (Python):
def main():

    n = int(input())
    A = list(map(int, input().split()))
    cnt = 0
    start = 1
    for i in range(len(A)):
        if A[i] != start:
            cnt += 1
        else:
            start += 1

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

if __name__ == "__main__":
    main()

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

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

if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
data = [int(s) for s in input().split()]
ini = 1
indData = []
for i in range(len(data)):
  if data[i] == ini:
    ini += 1
    indData.append(i)
ans = 0
if len(indData) == 1:
  if len(data) == 1:
    print(0)
    exit()
  else:
    print(len(data) -1)
    exit()
if len(indData) == 0:
  print(-1)
  exit()
for i in range(len(indData)-1):
  ans += indData[i+1] - indData[i] -1

ans += indData[0]
print(ans)

Solution (Python):

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

x=1
ans=0
for i in num:
    if x==i:
        x+=1
    elif x != i:
        ans+=1

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

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

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

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

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

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

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

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

sum = 0
counter = 1
left = 0

for i in range(left, n):
    if l[i] == counter:
        sum += i-left
        counter += 1
        left = i+1
        continue
sum += n-left

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

Solution (Python):


from collections import deque

N = int(input())
array = deque(list(map(int, input().split())))
ans, tmp, ctr = 0, 0, 1

for i in range(N):
    tmp = array.popleft()
    if tmp == ctr:
        ctr += 1
    else:
        ans += 1

if ctr > 1:
    print(ans)
else:
    print(-1)

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

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

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

	p = 0
	res = 0
	for a in vA:
		if p+1 == a:
			p += 1
		else:
			res += 1

	print(res if p else -1)

main()

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

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

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

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


if __name__ == "__main__":
    main()

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

Solution (Python):

N=int(input())
A=input()
a=1
for i in A.split():
    if int(i)==a:
        a+=1
if a==1:
    print(-1)
else:
    print(N-a + 1)

Solution (Python):
N = int(input())
li_str = input().split()
li_int = []
for i in li_str:
    li_int.append(int(i))
count= 1
num =  N + 1
for i in li_int:
    if i == count:
        num = count
        count += 1
print(N - num)

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

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

j = 0

i = 1
for tmp in arr:
    if i != tmp:
        j = j + 1
    else :
        i = i + 1
else:
    if j == len(arr):
        j = -1

print(j)

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

cnt = 0
pointer = 1

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

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

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

c = 0
e = len(A)
d = 1
for i in range(e):
  if A[i] == d:
    d = d + 1
  else:
    c = c + 1

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

Solution (Python):
n = int(input())
tmp = input().split(" ")
x = list()
for i in tmp:
  x.append(int(i))
c=0
for i in x:
  if i==(c+1):
    c+=1
br = n-c

if c==0:
  print("-1")
else:
  print(br)

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

ans = 0
break_tgt = 1

for i in range(n):
    if A[i] == break_tgt:
        break_tgt += 1
    else:
        ans += 1

if ans == n:
    ans = -1

print(ans)

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

for a in A:
	if a == num:
		num += 1
	else:
		ctr += 1
if num == 1:
	print(-1)
else:
	print(ctr)

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

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

if n == ans:
    ans = -1

print(ans)

Solution (Python):
def getdata_input():
    while True:
        yield input()

it=getdata_input()
N=int(next(it))
arr=[-1]*N
arr[0],*arr[1:]=map(int,next(it).split())
n=1
out=[]
i=-1
while True:
    try:
        i=arr.index(n,i+1)
        out.append(i)
        n+=1
    except ValueError:
        if i<N-1 and n>1 :
            out.append(N)
        break
if len(out) ==0: 
    print(-1)
else:
    i,j=0,0
    total=0
    for x in out:
        j=x
        total+=(j-i)
        i=j+1
        
    print(total)

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

s=list(S)

for i in range(n):
    s[i]=int(s[i])


def ikeruka(s):
    sum=0
    for i in range(len(s)):
        if s[i]==1:
            sum+=1

    if sum>=1:
        return True
    else:
        return False



if ikeruka(s):

    
    
    j=0
    l=1
    while j<=n-1:
        if s[j]==l:
            l+=1
            j+=1

            if j>n:
                break
            
        else:
            j+=1

    print(n-l+1)

else:
    print(-1)

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

Solution (Python):
n=int(input())
h=list(map(int,input().split()))
mn=min(h)
cnt=0
if(mn!=1):
    print("-1")
    exit()
i=1
for k in h:
    if(k==i):
        i=i+1
    else:
        cnt=cnt+1
print(cnt)

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

tmp = 1
count = 0
for b in a:
    if tmp == b:
        count += 1
        tmp += 1

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

Solution (Python):
import sys

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

    for i in a:
        if(i==num):
            num += 1

    if(num!=1):
        print(len(a) - num + 1)
    else:
        print('-1')

main()

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

bt = 0 
i = 0  
j = 0  

while i < n:
  while j < n:
    if array[j] == i+1:
      bt += 1
      break
      
    else:
      if j == n-1:
        if i == 0:
          bt = -1
          i = n+1
          j = n+1
          break
        else:
          i = n+1
          j = n+1
          break
          
    j += 1
  i +=1
  
if bt != -1:
  bt = n - bt
  
print(bt)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
i = 1
broken = 0
found = False
for v in a:
    if i == v:
        i += 1
        found = True
    else:
        broken += 1

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
li_A = list(map(int, input().split()))
count = 0
find = 1
for i in range(N):
    if li_A[i] == find:
        find += 1
    else:
        count += 1
if count < N:
    print(count)
else:
    print("-1")

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

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = 0
i = 0
while i + 1 <= len(a):
    
    if a[i] != i + 1:
        
        if i + 1 in a:
            
            del a[i:a.index(i + 1)]
        
        else:
            del a[i:]
        
    
    else:
        i += 1

if len(a) == 0:
  print(-1)

else:
    print(n - len(a))

Solution (Python):
a=int(input())
lis=list(map(int,input().split()))
suu=0
ans=0
x=0
while len(lis)>x:
  if lis[x]==suu+1:
    suu+=1
  else:
    ans+=1
  x+=1
if ans==a:
  print(-1)
else:
  print(ans)

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

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

Solution (Python):


import sys
from collections import deque

def input_data(d=""):
  t = sys.stdin.read()
  if t:
    return t
  else:
    if d[0] == "\n":
      d = d[1:]
    if d[-1] == "\n":
      d = d[:-1]    
    return d

A, *B  = map(int,input_data().split())

m = []

if 1 not in B:
  print(-1)
else:
  out = 0
  c = 1
  for i in B:
    if i == c:
      c+=1
    else:
      out+=1
  print(out)

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

i=0;j=0
while(i<N):
    if A[i]==j+1:
        j+=1
    i+=1

print(N-j if j!=0 else -1)

Solution (Python):
import sys

input = sys.stdin.readline


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

        broken = 0
        next_target = 1
        for i in range(N):
            if a[i] != next_target:
                broken += 1
            else:
                next_target += 1

        if broken < N:
            print(broken)
        else:
            print(-1)



if __name__ == '__main__':
    AtCoder().main()

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):
def main(sample_file = ''):

    """ convenient functions
    
    
    
    
    
    """

    """convenient decorator
    
    
        
        
        
        
        
        
        
        
        
        
    """
    
    
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product 
    
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  
        b, e = 2, 0  
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict 
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest 
    from copy import deepcopy, copy 
    import operator
    from operator import itemgetter 
    
    
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd 
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)
    def make_divisors(n, reversed=False):
        """create list of divisors
        
        Args:
            number (int): number from which list of divisors is created
            reversed (bool, optional): ascending order if False. Defaults to False.
        
        Returns:
            list: list of divisors
        """
        divisors = set()
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divisors.add(i)
                divisors.add(n//i)
        return sorted(list(divisors),reverse=reversed)
    
    
    
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) 
    def modinv(a, p = MOD):
        
        
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        
        
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    class UnionFindTree:
        """union find tree class
        TODO: fix this description...
        how to use (example):
        >>  uf = UnionFindTree(N) 
        >>  if uf.find_root(a) == uf.find_root(b):
        >>      do something
        >>  else:
        >>      do something
        >>      uf.unite(a, b)
        """
        def __init__(self, N):
            self.root = [-1] * (N+1)
            self.rank   = [0]  * (N+1)
            self.connected_num = [1] * (N+1)
    
        def find_root(self,x):
            root = self.root
            while root[x] != -1:
                x = root[x]
            return x
    
        def unite(self,x,y):
            root = self.root
            rank = self.rank
            connected_num = self.connected_num
            find_root = self.find_root
    
            rx = find_root(x)
            ry = find_root(y)
            if rx != ry:
                if rank[rx] < rank[ry]:
                    root[rx] = ry
                    rx,ry = ry,rx
                else:
                    if rank[rx] == rank[ry]:
                        rank[rx] += 1
                    root[ry] = rx       
                connected_num[rx] += connected_num[ry]

    
    
    
    
    

    def BellmanFord(N, M, ABC, vertex_start, vertex_end, value_if_inf = -1, find_shortest = False):
        """to calculate furthest or shortest length between vertex_start and vertex_end using BellmanFord algorithm
        
        Args:
            N (int): number of vertices
            M (int): number of edges
            ABC (list): [(ai, bi, ci) for _ in range(N)] where i-th edge is directed from vertex ai to vertex bi and the length is ci 
            vertex_start (int): start vertex. usually use 0.
            vertex_end (int): end vertex. usually use N-1.
            value_if_inf (int or string as you like, optional): value you want when the furthest (or shortest) distance is infinite (or -infinite). Defaults to -1.
            find_shortest (bool, optional): choose False to find furthest path. Defaults to False.
        
        Returns:
            int or string: normally int (but can be str if you set value_if_inf to str)
            
        Example:
                N, M, P = R()
                ABC = [R() for _ in range(M)]
                ABC = [(a-1, b-1, c-P) for a, b, c in ABC]
                print(BellmanFord(N, M, ABC, 0, N-1, value_if_inf = 'inf'))

        """

        def make_reachable_list(N, M, ABC, vertex_start, vertex_end):
            reachable_to_direct = defaultdict(list)
            reachable_from_direct = defaultdict(list)
            reachable_from_start = [False] * N
            reachable_to_end = [False] * N
            reachable_from_start[vertex_start] = True
            reachable_to_end[vertex_end] = True
            reachable_from_both_sides = [False] * N
            dfs_from_start = []
            dfs_to_end = []
            for a, b, c in ABC:
                reachable_to_direct[a].append(b)
                reachable_from_direct[b].append(a)
                if a == vertex_start:
                    dfs_from_start.append(b)
                    reachable_from_start[b] = True
                if b == vertex_end:
                    dfs_to_end.append(a)
                    reachable_to_end[a] = True
            while dfs_from_start:
                v = dfs_from_start.pop()
                for i in reachable_to_direct[v]:
                    if not reachable_from_start[i]:
                        reachable_from_start[i] = True
                        dfs_from_start.append(i)
            while dfs_to_end:
                v = dfs_to_end.pop()
                for i in reachable_from_direct[v]:
                    if not reachable_to_end[i]:
                        reachable_to_end[i] = True
                        dfs_to_end.append(i)
            for i in range(N):
                reachable_from_both_sides[i] = reachable_from_start[i] and reachable_to_end[i]
            return reachable_from_both_sides
        
        reachable_from_both_sides = make_reachable_list(N, M, ABC, vertex_start, vertex_end)
        
        if find_shortest:
            dist = [INF for i in range(N)]
        else:
            dist = [-INF for i in range(N)]
        
        dist[vertex_start] = 0
        for i in range(N):
            updated = False
            for a, b, c in ABC:
                if not reachable_from_both_sides[a]:
                    continue
                elif find_shortest:
                    update_condition = dist[a] + c < dist[b]
                else:
                    update_condition = dist[a] + c > dist[b]
                if dist[a] != INF and update_condition:
                    dist[b] = dist[a] + c
                    updated = True
                    if i == N-1:
                        return value_if_inf
            if not updated:
                break
        return dist[vertex_end]

    """ initialize variables and set inputs
    
        
        
            
            
    
        
        
        
        
        
        
        
    
        
        
        
        
    
        
        
    """

    
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    r_float = lambda: float(r())
    R = lambda: list(map(int, r().split()))
    R_str = lambda: r().split()
    R_map = lambda: map(int, r().split())
    R_float = lambda: list(map(float, r().split()))
    R_tuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    
    
    
    
    
    
    
    """

    
    if sample_file:
        sys.stdin = open(sample_file)
        
    
    

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

    """memo: how to use defaultdict of list
    
    Dic = defaultdict(list)
    
    Dic[x].append(y)
    
    for k, v in Dic.items():
    """
    
    """memo: how to solve binary problems
    
    >>> a = 5
    >>> bin_str_a = format(a, '
    >>> print(bin_str_a)
    0b0101 
    """
    
    """memo: how to solve the problem
    creating simple test/answer
    greed
    simple dp
    graph
    """

if __name__ == '__main__':
    main()

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

hit = 0
kazu = 1
for i in a:
    if i == kazu:
        hit += 1
        kazu += 1

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

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

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

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

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

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

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

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

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

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

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

d=0
c=1
for i in range(len(L)):
    if L[i]==c:
        c+=1
    else:
        d+=1

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

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

Solution (Python):

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

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

if ans == N:
    ans = -1

print(ans)