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())
a = list(map(int,input().split()))
now = 1
for i in range(N):
    if now == a[i]:
        now += 1
if now == 1:
    print("-1")
else:
    print(N - now + 1)

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

cnt = 0
for i in l:
    if (cnt+1 == i):
        cnt+=1

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

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

ans = 0

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
cur = 1
broke = 0
for a in A:
  if cur == a:
    cur += 1
  else:
    broke += 1

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

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

target = 1 
bk = 0 
for i in a:
        if i == target:
                target += 1
                continue
        else:
                bk += 1
if target == 1:
        print(-1)
else:
        print(bk)

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

count = 1
break_num = 0

for item in items:
    if item == count:
        count += 1
    else:
        break_num += 1

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

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

Solution (Python):

import sys

N = int(input())
A = [int(v) for v in sys.stdin.readline().split()]

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

Solution (Python):

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

l = []
i = 1
for a in A:
    if a == i:
        l.append(a)
        i += 1
if len(l) == 0:
    print(-1)
else:
    print(n - len(l))

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

r = -1
x = 1

for i in range(n):
    if l[i] == x:
        x += 1
if x > 1:
    r = n - x + 1
print(r)

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

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


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

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

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

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

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

k = 0
for ai in an:
  if ai == k+1:
    k += 1
if k == 0:
  print(-1)
else:
  print(n-k)

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

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

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

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

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    no = 1
    cnt = 0
    for i in range(n):
        if no == a[i]:
            cnt += 1
            no += 1
    print(n - cnt if cnt != 0 else -1)


if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
rengas = [int(i) for i in input().split()]
ns = 1
c = 0
if 1 in rengas:
  for i in rengas:
    if i == ns:
      ns += 1
    else:
      c += 1
  print(c)
else:
  print(-1)

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

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

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

if ans != 0 and tmp ==1:
  print(-1)
else:
  print(ans)

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

if 1 not in a:
    print(-1)
else:
    now = a.index(1)
    if now == N-1:
        print(N-1)
    else:
        ans = now
        search = 2
        now += 1
        while now <= N-1:
            if a[now] == search:
                search += 1
            else:
                ans += 1
            now += 1
        print(ans)

Solution (Python):
from collections import deque

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

blk = 1
cnt = 0

for i in range(N):
    a = A.popleft()

    if a == blk:
        blk += 1
    else:
        cnt += 1

if blk == 1:
    cnt = '-1'

print(cnt)

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

cnt = 1
remove = 0
for a in A:
  if a == cnt:
    cnt += 1
  else:
    remove += 1

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

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

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

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

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

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

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



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

if number==1:
  print(-1)
else:
  print(break_count)

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

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

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

cnt = 0
tmp = 1
i = 0
for _ in range(N):
  D = d.popleft()
  if D == tmp:
    tmp += 1
    i = 1
  else:
    cnt += 1
    
if i != 1:
  print(-1)
else:
  print(cnt)

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

for ai in a:
    if ai == count:
        count += 1

if count == 1:
    ans = -1
else:
    ans = n - count + 1

print(ans)

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

o=0
c=1

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

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

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

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

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

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

count = 0

for i in a:
    count += int((count+1) == i)

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

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

Solution (Python):
num = int(input())
num_list = [int(s) for s in input().split()]
count = 1
hantei = False
for i in range(0,num):
    if num_list[i] == count:
        count+=1
        hantei = True
if hantei == False:
    print("-1")
else:
    print(num-count+1)

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

ans = 1
for i, a in enumerate(A):
    if a == ans:
        ans += 1
ans -= 1
if ans == 0:
    print(-1)
else:
    print(len(A) - ans)

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):
    ans = -1

print(ans)

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

cnt=0
now=1

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

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

Solution (Python):
n = int(input())
test = 1
arr = [int(i) for i in input().split()]
for i in range(n):
    if arr[i] == test:
        
        test += 1
if n == 1 and test == 1:
    print(0)
elif test == 1:
    print(-1)
else:
    print(n - test + 1)

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

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

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

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


def solve():
    N = int(input())
    an = list(map(int,input().strip().split()))
    counter=1
    chk=False
    for i in range(N):
    	if counter == an[i]:
    		chk=True
    		counter+=1
    if chk:
    	print(N-counter+1)
    else:
    	print(-1)


if __name__ == '__main__':
    solve()

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

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

cnt = 0
ptr = 1

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

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

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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


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

N = INT()
A = LIST()
c = 1
ans = 0
for i in range(N) :
  if A[i] == c:
    c += 1
    ans += 1

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

Solution (Python):
n  = int(input())
xs = [int(x) for x in input().split()]
c  = 0
y  = 1

for x in xs:
	if x == y:
		y += 1
	else:
		c += 1

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

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

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

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

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

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

for i in range(1, N+1):
    if cur >= N:
        break
    while cur < N and a[cur] != i:
        cur += 1
        ans += 1
    cur += 1
print(ans if N != ans else -1)

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


counter = 1
for i in A:
        if i == counter:
                counter += 1
                continue

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

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

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

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

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

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

i = 0
c = 1
cnt = 0
while i < n:
    if input_list[i] == c:   
        c += 1
    else:
        cnt += 1     
        
    i += 1

print(cnt if c > 1 else '-1')

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

count = 0
for a in a_list:
    if a == count + 1:
        count += 1

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

Solution (Python):
n  = int(input())
xs = [int(x) for x in input().split()]
c  = 0
y  = 1

for x in xs:
	if x == y:
		y += 1
	else:
		c += 1

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

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

x = 1
for ai in a:
    if ai == x:
        x += 1
if N-x+1 == N:
    print("-1")
else:
    print(N-x+1)

Solution (Python):
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]



def A():
    a = I()
    b = I()
    print(6 - a - b)
    return



def B():
    n = I()
    s, t = input().split(' ')
    ans = []
    for i in range(n):
        ans.append(s[i])
        ans.append(t[i])
    print(''.join(ans))
    return



def C():
    def GCD(a, b):
        if (b == 0):
            return a
        else:
            return GCD(b, a % b)

    a, b = LI()
    print(a * b // GCD(a, b))
    return



def D():
    n = I()
    a = LI()
    cnt = 0
    for i in range(n):
        if a[i] == cnt + 1:
            cnt += 1
    if cnt == 0:
        print(-1)
    else:
        print(n - cnt)
    return



def E():
    return



def F():
    return



def resolve():
    D()
    return



if __name__ == "__main__":
    D()

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

target=1
count=0

for i in ls:
    if i==target:
        target+=1
    else:
        count+=1

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

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

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

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

Solution (Python):
from bisect import bisect_left

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


def lis(li):
    lis_li = [li[0]]
    for i in li:
        if i > lis_li[-1]:
            lis_li.append(i)
        else:
            lis_li[bisect_left(lis_li, i)] = i
    return lis_li

rA = lis(A)

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

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

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

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

Solution (Python):


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

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

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

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

Solution (Python):

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

for item in A:
    if item != check_num:
        ans += 1
    else:
        check_num += 1
        
if ans == N:
    print(-1)
else:
    print(ans)

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

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

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

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

i = 1
c = 0
ans = 0

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

while c < N:
  if a[c] == i:
    i += 1
  else:
    ans += 1
  
  c += 1

print(ans)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
p=n
f=1
for i in range(n):
    if l[i]==f:
        p-=1
        f+=1
if min(l)!=1:
    print(-1)
else:
    print(p)

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

if __name__=='__main__':
    main()

Solution (Python):
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    a=LIST()
    count = 1
    breakb = 0
    for i in range(n):
        if a[i]==count:
            count+=1
        else:
            breakb += 1
    if count==1:
        print(-1)
    else:
        print(breakb)
    
            
if __name__ == '__main__':
    do()

Solution (Python):


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

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

print(ans if ans < N else -1)

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

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

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

Solution (Python):
import sys; readline = sys.stdin.readline
from collections import deque

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

j = 1

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

if j == 1:
    print(-1)
else:
    print(len(a) - (j - 1))

Solution (Python):

import sys
import math
import collections


n=int(input())
tmp = input().split()
s = list(map(lambda a: int(a), tmp))

ind=0
for i in range(n):
	if(s[i]==ind+1):
		ind+=1

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

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

count = 1
for i in a:
    if i == count:
        count +=1
if count-1 == 0:
    print(-1)
    exit()

print(N-count+1)

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

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

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

count=0
for ai in aa:
  if ai == count+1:
    count+=1

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

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

tmp = 1
cnt = 0

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

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

cnt = 1
ans = 0
flg = False
for i in range(n):
    if cnt == a[i]:
        flg = True
        cnt += 1
    else:
        ans += 1
print(ans) if ans >= 0 and flg else print(-1)

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

count = 1
ans = 0
invalid = True

for a in A:
  if a != count:
    ans += 1
  else:
    invalid = False
    count += 1

if invalid:
  print(-1)
else:
  print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[]
sum=0
for i in range(n):
    j=i+1-sum
    if a[i]!=j:
        sum+=1
    else:
        b.append(a[i])
def ans():
    if len(b)==0:
        print(-1)
        return
    for i in range(len(b)):
        if b[i]!=i+1:
            print(-1)
            return
    print(sum)
ans()

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

Solution (Python):
n = int(input())
L = [int(i) for i in input().split()]
breaknum = 0
target = 1

for i in range(n):
  if L[i] != target:
    breaknum += 1
  else:
    target += 1

if target != 1 and breaknum != 0:
  print(breaknum)
elif breaknum == n:
  print(-1)
else:
  print(0)

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

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

if broke == n:
    print("-1")
else:
    print(broke)

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

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

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


hope_number = 1


ans = 0

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

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

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

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

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

Solution (Python):
def solve():
    l=[0]
    count=0
    for i in a:
        if i==l[-1]+1:
            l+=[i]
        else:
            count+=1
    print(count if len(l)!=1 else -1)

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
s=1
c=0
for i in a:
  if i==s:
    s+=1
    c+=1

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

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

result = 0
pre_num = 0

for a in As:
    if a == pre_num+1:
        pre_num += 1
    else:
        result += 1

if pre_num == 0:
    result = -1

print(result)

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



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

    ans = 0
    count = 1
    for i in A:
        if i == count:
            count += 1

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




    


if __name__ == '__main__':
    main()

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

n = int(readline())
a = list(map(int, read().split()))
ans = 0
cnt = 1
for a_ in a:
    if a_ == cnt:
        cnt += 1
    else:
        ans += 1


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

Solution (Python):


n = int(input())
data = list(map(int, input().split(' ')))

i = 1
if 1 not in data:
    print(-1)
else:
    for num in data:
        if num == i:
            i += 1
    print(n - i + 1)

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

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

Solution (Python):
inpl = lambda: list(map(int,input().split()))
N = int(input())
a = inpl()
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()))
if 1 not in A:
  print(-1)
  exit()
ans = 0
x = 1
for i in range(N):
  if A[i] != x:
    ans += 1
  else:
    x += 1
print(ans)

Solution (Python):
n=int(input())
a=list(input().split(" "))
an=0
co=1

for i in range(n):
    if int(a[i])==co:
        co+=1
    else:
        an+=1

if co==1:
    print("-1")
else:
    print(an)

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

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

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

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

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

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

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

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

now = 0
s = 1

ans = 0

while now != N:
    
    if s != a[now]:
        ans += 1
    else:
        s += 1
    
    now += 1

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

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

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

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

if count == 1:
  print('-1')
else:
  Ans = N - count + 1
  print(Ans)

Solution (Python):
n  = int(input())
xs = [int(x) for x in input().split()]
c  = 0
y  = 1

for x in xs:
	if x == y:
		y += 1
	else:
		c += 1

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

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

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

n = n-1

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

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

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

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):
def main():
    N = int(input())
    a = [int(i) for i in input().split()]

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

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

if __name__ == "__main__":
    main()

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

index = 0
found = 0

for i in range(1, len_arr+1):
    try:
        index = arr.index(i, index)
        found += 1
    except ValueError:
        break

if found:
    print(len_arr - found)
else:
    print(-1)
exit(0)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x)-1 for x in sys.stdin.readline().split()]

def main():
    N = I()
    A = LI()
    ans = 0
    cnt = 0
    cur = 0
    for i in range(N):
        if A[i] == cur:
            ans += cnt
            cnt = 0
            cur += 1
        else:
            cnt += 1
    if cur != 0:
        ans += cnt
    else:
        ans = -1
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = map(int, input().split())

    ans, i = 0, 1
    for a in A:
        if a != i:
            ans += 1
        else:
            i += 1

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


main()

Solution (Python):
import math
import random
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
N = int(input())
S = [int(i) for i in input().split()]
num = 1
for i in range(N):
    if S[i] == num:
        num += 1
if num != 1:
    print(N-num+1)
else:
    print(-1)

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

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

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

if ans <n:
    print(ans)
else:
    print("-1")

Solution (Python):



def solve(*args: str) -> str:
    n = int(args[0])
    A = tuple(map(int, args[1].split()))

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

    return str(ret if 1 < search else -1)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))