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-----
3
2 1 2

-----Sample Output-----
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.

Difficulty: interview

Starter code:

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


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


n = int(input())
a = list(map(int, input().split()))
res = 0
num = 1
if 1 not in a:
    print(-1)
else:
    for ai in a:
        if ai == num: num += 1
        else: res += 1
    print(res)

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

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

N = int(input())

a = map(int, input().split())
A = []
count = 0
for i in a:
    if i == count + 1:
        A.append(i)
        count += 1
if A:
    print(N - count)
else:
    print('-1')

N = int(input())
L = list(map(int, input().split()))
c = 1
for l in L:
  if l == c:
    c += 1
r = N - c + 1
if r == N:
  print(-1)
else:
  print(r)

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

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

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

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

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

l = 1
s = 0

for i in A:
  if i == l:
      #print(i)
      l += 1
      #print(l)

if l == 1:
	ans = -1
else:
	ans = N-l+1

print(ans)

# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     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

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


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

next_number = 1
cnt = 0
for a in A:
  if a == next_number:
    next_number += 1
  else:
    cnt += 1
if cnt == len(A):
  print('-1')
else:
  print(cnt)

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


#!/usr/bin/env python3
def main():
    N = int(input())
    a = [int(x) for x in input().split()]

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


def __starting_point():
    main()

__starting_point()

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

ans = 1
cnt = 0

if ans not in a:
  print(-1)
  return
for i in a:
  if i == ans:
    ans += 1
    continue
  cnt += 1
  
print(cnt)

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

c = 1
for i in a:
    if i == c:
        c += 1
print(n-c+1 if c > 1 else -1)

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

min = num_list[0]
for j in range(1, n, 1):
    if num_list[j] < min:
        min = num_list[j]

if min != 1:
    ans = -1
else:
    target = 1
    cnt = 0
    for i in range(len(num_list)):
        if num_list[i] == target:
            target += 1
        else:
            cnt += 1
    ans = cnt

print(ans)

N=int(input());A=list(map(int,input().split()));j=1;fg=0
if N==1:
    if A[0]==1:print(0)
    else: print(-1)
else:
    for i in A:
        if i==j:j+=1
        else:fg+=1
    if j>1:print(fg)
    else: print(-1)

n = int(input())
a = [int(i) for i in input().split()]
k = 0
flg = False
for ai in a:
  if ai == k + 1:
    k += 1
  else:
    flg = True
if k == 0 and flg:
  print(-1)
else:
  print(n - k)

import math
import statistics
a=int(input())
#b=int(input())
# c=[]
# for i in b:
#     c.append(i)
# e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#j = [input() for _ in range(3)]
# h = []
# for i in range(e1):
#     h.append(list(map(int,input().split())))
ans=0
count=0
for i in range(a):
    if ans+1 == f[i]:
        ans=f[i]
        count+=1
if count>0:   
    print(len(f)-count)
else:
    print(-1)

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

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

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

#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main2():
    numbers=[]
    N = int(input())
    numbers=list(map(int,input().split()))
    n=1

#条件が1<=n<=200kのため1から順に数えてlist内を調査した場合の最大値+1をnに記入
    for x in numbers:
        if x ==n:
            n+=1

#条件から+1まで数えてしまうため、nを+1して調整
    answer = N - n +1

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

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))
    buffer=[0]
    for i in range(1,n+1):
        search_range=numbers[i-1:]
        out_range=len(numbers[:i-1])
        if i not in search_range and len(buffer)==1:
            print(-1)
            return
        elif i not in search_range or i==n:
            break
        else:
            index=search_range.index(i)
            buffer.append(index-sum(buffer))
    print(sum(buffer))

def __starting_point():
    main2()
__starting_point()

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

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

n = int(input())
A = list(map(int, input().split()))
mx = 0
tot = 0

for i in range(n):
    if(A[i] != mx + 1) :
        continue
    mx = A[i]
    tot += 1

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

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

cnt=0
m=1

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


import sys

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


if A.count(1) == 0:
  print((-1))
  return
else:
  
  cnt = 0
  for a in range(len(A)):
    if A[a] == cnt+1:
      cnt += 1
  print((len(A)-cnt))



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(N + 1 - n)
else:
  print(-1)

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

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

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

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

a = int(input())
b = list(map(int,input().split()))
c = 1
ans = 0
for i in b:
    if i == c:
        c += 1
    else:
        ans += 1
if ans == a:
    ans = -1
print(ans)

import math
n=int(input())
A=list(map(int,input().split()))
num=1
brk=0
for i in range(n):
  if A[i]==num:
    num+=1
  else:
    brk+=1

if num==1 and brk!=0:
  print(-1)
else:
  print(brk)

#!/usr/bin/env python3
import sys
from itertools import chain


def solve(N: int, A: "List[int]"):
    cnt = 0
    for a in A:
        if a == cnt + 1:
            cnt += 1

    if cnt == 0:
        return -1
    return N - cnt


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    answer = solve(N, A)
    print(answer)


def __starting_point():
    main()

__starting_point()

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

n = int(input())
a = list(map(int, input().split()))
c = 1
for j in a:
    if j==c:
        c += 1
 
if c==1:
    print(-1)
else:
    print(n-c+1)

n=int(input())
a=list(map(int,input().split()))
i,ans,j=1,0,0

while j<n:
    if a[j]==i:
        i+=1
    else:
        ans+=1
    j+=1
if ans==n:
    print(-1)
else:
    print(ans)

# AtCoder Beginner Contest 148
# D - Brick Break

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

targetnum=1
breaknum=0

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


N = int(input())
a = list(map(int, input().split()))
n = 1
C = 0
for ai in a:
    if ai != n:
        C += 1
    else:
        n += 1
if n == 1:
    print('-1')
else:
    print(C)

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

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

N = int(input())

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

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

# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 01:08:27 2020

@author: liang
"""

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

count = 1
for a in A:
    if a == count:
        count += 1
if count == 1:
    ans = -1
else:
    ans = N - count + 1
print(ans)

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

n = int(input())
l = list(map(int,input().split()))
ans = 0
x = 1
for i in l:
    if i == x:
        x += 1
    else:
        ans += 1

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


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

ans = 0
i = 0
j = 0
while i < n:
    if a_l[i] == j+1:
        j += 1
        i += 1
        continue
    ans += 1
    i += 1
if ans > n-1:
    print('-1')
else:
    print(ans)

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 + 1 - n)

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

i = 1
cnt = 0

for char in arr:
    if char == i:
        i += 1
    else:
        cnt += 1

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


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

N = int(input())
li = list(map(int, input().split()))
li_com = [i+1 for i in range(N)]
an = 0
com = 0
for i in range(N):
    if li_com[com] == li[i]:
        com += 1
    else:
        an += 1

if com == 0:
    print(-1)
else:
    print(an)

N = int(input())
a = [int(i) for i in input().split()]
ans = 0
l = 1
for i in range(N):
    if l == a[i]:
        l += 1
    else:
        ans += 1
if ans == N:
    print(-1)
else:
    print(ans)

#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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


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

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

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


def main():
    solve()


def __starting_point():
    main()

__starting_point()

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

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

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

l = []
min_num = 0
for i in a:
    if i == min_num + 1:
        l.append(i)
        min_num += 1

print(N-len(l))

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

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

N = int(input())
a = map(int, input().split())
counter = 0
for ai in a:
    if counter + 1 == ai:
        counter += 1
print(N - counter if counter != 0 else '-1')

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

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

n = int(input())
A = list(map(int,input().split()))
tmp, cnt = 1, 0

for a in A:
  if a != tmp: cnt += 1
  else: tmp +=1

print(-1 if A.count(1) == 0 else cnt)

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

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

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

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

N = int(input())
A = list(map(int,input().split()))
ans = 0
n = 1

for a in A:
  if a==n:
    n+=1
  else:
    ans+=1

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

import math
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
    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 make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def size(self, x):
        return -self.parents[self.find(x)]
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
 
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
 
    def group_count(self):
        return len(self.roots())
 
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
 
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
mod = 10**9 + 7
sigma = lambda x : x*(x+1)//2

#--maincode----------------

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

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

def __starting_point():
    main()

__starting_point()

n=int(input())
a=list(int(x) for x in input().split())

count=0
z=True
j=0

if  1 not in a:
    print(-1)
else:
    for k in range(j,n):
        if a[k]==count+1:
            j=k
            count=count+1

    print(n-count)

n=int(input())
a=list(map(int,input().split()))
count=1
chk=False
for i in range(1,n+1):
  if a[i-1]==count:
    chk=True
    count+=1
print(n-count+1 if chk else -1)

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

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

N = int(input())
A = list(map(int, input().split()))
min = 1
check = True
count = 0
for i in range(N):
  if A[i] != min:
    A[i] = 0
    count += 1
  elif A[i] == min:
    min += 1
if A == [0] * N:
  print(-1)
else:
  print(count)

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

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

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


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

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

n = int(input())
a = list(map(int,input().split()))
cnt = 0
i,j = 0,0
while i<n and j<n:
    if a[i]==j+1:
        cnt+=1
        j+=1
    i+=1
print(-1 if 1 not in a else n - cnt)

n = int(input())
a = list(map(int, input().split()))
c = 1
for j in a:
    if j==c:
        c += 1

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


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

n=int(input())
a=list(map(int,input().split()))
b=len(a)
result=1
i=0
j=0
while True:
    if a[i]==result:
        result+=1
    i+=1
    if i>=b:
        break
if result==1:
    print(-1)
else:
    print(b-result+1)

n = int(input())
num = list(map(int,input().split()))
cnt = 1
ans = 0
if 1 not in num:
    print(-1)
    return
for i in range(n):
    if num[i] == cnt:
        cnt += 1
    else:
        ans += 1
print(ans)

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

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

N = int(input())
block = list(map(int,input().split()))
a = 1
for i in block:
  if i == a:
    a += 1
if a==1:
  print(-1)
else:
  print(len(block)-a+1)

import sys


def resolve(in_):
    N = int(next(in_))
    A = tuple(map(int, next(in_).split()))
    
    ans = 0
    x = 1
    for a in A:
        if x == a:
            x += 1
        else:
            ans += 1

    if N == ans:
        ans = -1
    return ans


def main():
    answer = resolve(sys.stdin)
    print(answer)


def __starting_point():
    main()

__starting_point()

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

if n == 1 and al[0] == 1:
    print(0)
else:
    i, j, num, ans = 0, 0, 1, 0
    while i < n:
        if al[i] != num:
            i += 1
        else:
            ans += i-j
            j = i+1
            num += 1
            i += 1

    # print(i, j, ans)

    if num != 1 and j != n:
        ans += i-j

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

def main():
    N = int(input())
    A = list(map(int, input().split()))
    breakcount = 0
    cnt = 1
    for i in range(N):
        if A[i] != cnt:
            breakcount += 1
        else:
            cnt += 1
    if cnt == 1:
        print((-1))
        return
    print(breakcount)

def __starting_point():
    main()

__starting_point()

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

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

print(ans)

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



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

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

print(-1 if i == 1 else N - i + 1)

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

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

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

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

cnt = 0

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

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

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

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

cnt = 0
idx = 1
for i, a in enumerate(A):
    if idx == a:
        idx += 1
    else:
        cnt += 1

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

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

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

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

if tmp==1:
    ans=-1

print(ans)

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

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

cnt = 0
for i in a:
    if i == cnt + 1:
        cnt += 1

print(N-cnt)


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

flag_ary = [0] * (N+1)

counter = 0
cur = 1
for i in l:
    if i == cur:
        counter += 1
        cur += 1
if counter == 0:
    print((-1))
else:
    print((N - counter))


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

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

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

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

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

N = int(input())
con = 1
set = 0
s = list(map(int, input().split()))
for i in s:
  if con == i:
    set += 1
    con += 1
if set == 0:
  print((-1))
else:
  ans = len(s) - set
  print(ans)
    
    



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

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

chk = 1
cnt = 0
for i in range(n):
    if A[i] == chk:
        cnt += 1
        chk += 1

print(len(A) - cnt)

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

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

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

# coding: utf-8

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = -1
    tmp = 1
    flg = False

    for a in A:
        if a == tmp:
            tmp += 1
            flg = True

    if flg:
        ans = N - tmp + 1

    print(ans)

def __starting_point():
    main()

__starting_point()

n = int(input())
A = list(map(int, input().split()))
prev = -1
cnt = [0]
i = 0
for a in A:
    if prev==-1 and a==1:
        prev = a
    elif a == prev+1:
        prev = a
    else:
        i += 1
if prev == -1:
    print(-1)
else:
    print(i)

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

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