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()))
count = 1
number = 0
for i in range(N):
  if a[i] == count:
    count += 1
  else:
    number += 1
if number == N:
  print(-1)
else:
  print(number)

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

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

index = 1
count = 0
for a in A:
  if a == index:
    index += 1
  else:
    count += 1
if count == n:
  count = -1
    
print(count)

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

itr = 0
num = 0

while(itr < n):
    if(a[itr] == num+1):
        num +=1
    itr += 1

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

Solution (Python):
N = input()
a = [int(x) for x in input().split()]
ans, cur = 0, 1
for ai in a:
    if ai == cur:
        cur += 1
    else:
        ans += 1
print(ans if len(a) != ans else -1)

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

base=1
count=0

if 1 in a:
    for i in range(N):
        if a[i]==base:
            count+=1
            base+=1
        else:
            pass

    
    print((N-count)%N)
else:
    print(-1)

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

Solution (Python):

import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    A = LMIIS()

    num_broken = 0
    pre_required = 0
    for i, a in enumerate(A):
        required = i-(a-1)
        if required != num_broken:
            num_broken += 1
    print(num_broken if num_broken < N else -1)




if __name__ == '__main__':
    main()

Solution (Python):
n,*a=map(int,open(0).read().split())

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

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

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

num = 1
cnt = 0

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

if num == 1:
    print("-1")
else:
    print(cnt)

Solution (Python):

if __name__ == '__main__':
    N=int(input())
    A=list(map(int,input().split()))
    temp=[]
    i=1
    for id,a in enumerate(A):
        if a==i:
            temp.append(a)
            i+=1
    ans=N-len(temp)
    if temp.__len__()==0:
        print(-1)
    else:
        print(ans)

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

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

ans = 0
num = 1
for a in a_array:
    if a == num:
        num += 1
    else:
        ans += 1
print(ans if ans != N else -1)

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

Solution (Python):
from collections import deque
n = int(input())
A = deque(map(int, input().split()))

next_ = 1
cnt = 0
while len(A) > 0:
  i = A.popleft()
  if i == next_:
    next_ += 1
  else:
    cnt += 1
if cnt == n:
  cnt = -1
print(cnt)

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

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

Solution (Python):
from collections import deque
n = int(input())
A = deque(map(int, input().split()))

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

Solution (Python):
from collections import deque
n = int(input())
A = deque(map(int, input().split()))

cnt = 0
flag_empty = False
flag_end = False
if not 1 in A:
  cnt = -1
else:
  for i in range(1, n+1):
    if not i in A:
      cnt += len(A)
      break
    while 1:
      a = A.popleft()
      if len(A) == 0: 
        flag_empty = True
        break
      if a != i:
        cnt += 1
      else:
        break
    if flag_empty:
      break
   
print(cnt)

Solution (Python):


N = int(input())
A = list(map(int, input().split()))
a = 1
block = []
for i in range(N):
    if A[i] == a:
        block.append(A[i])
        a += 1
    else:
        continue
if len(block) > 0:
    print(N - len(block))
else:
    print(-1)

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

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

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

chk=1
for i in a:
  if i==chk:
    chk+=1
if chk==1:
  print(-1)
else:
  print(len(a)-chk+1)

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

curr = 1
ans = 0
for num in nums:
    if num != curr:
        ans += 1
    else:
        curr += 1
if ans == n:
    print('-1')
else:
    print(ans)

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

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

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

res = 0

count = 1

for i in t:
    if i == count:
        count += 1
        res += 1
if res == 0:
    print(-1)
else:
    print(n-res)

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

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

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

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

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


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

print(n-cnt+1)

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

Solution (Python):
def gcd(a, b):
    if a < b:
        t = a
        a = b
        b = t
    if b == 0:
        return a
    return gcd(b, a % b)

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

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

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

Solution (Python):
n = int(input())
dat = list(map(int, input().split()))
import collections
dat = collections.deque(dat)
alen = len(dat)
t = 1
res = 0
while len(dat) != 0:
    c = dat.popleft()
    if c == t:
        t+=1
    else:
        res += 1
if  res == alen:
    print("-1")
else:
    print(res)

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

seq_len = 0

for el in arr:
    if el == seq_len+1:
        seq_len += 1


print(N - seq_len if (seq_len) else "-1")

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

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

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

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

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

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

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

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

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

if ans == N:
    ans = -1

print(ans)

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

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

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

count = 0

num = 1
for a in al:
    if a == 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()))

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

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

kept = 0
for ai in a:
    if ai == kept + 1:
        kept += 1

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

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

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

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

count = 0
num = 1

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

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

Solution (Python):
N = int(input())
A = map(int, input().split())
current = 1
ans = 0

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

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

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

if na[0] == 1:
    for i in a:
        if i == res:
            res += 1
        else:
            ans += 1
    print(ans)
else:
    print(-1)

Solution (Python):

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

L = [i+1 for i in range(N)]

cnt = 0
k = 0
for j in A:
  if j == L[k]:
    k += 1
  else:
    cnt += 1 

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

Solution (Python):
import sys
stdin = sys.stdin
import numpy as np

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n = ni()
a = na()
f = 1
cnt = 0
for ai in a:
    if ai == f:
        f += 1
        cnt += 1
if cnt == 0:
    print(-1)
else:
    print(n - cnt)

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

bef=1
ans=0

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

for i in range(n):
    if A[i]==bef:
        bef+=1
        ans+=1
print(n-ans)

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

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

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

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

cnt = 1
ans = 0

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

for num in a:
    if num == cnt:
        cnt+=1
    else:
        ans+=1

print(ans)

Solution (Python):

import sys


def solve(N: int, a: "List[int]"):
    if not 1 in a:
        print(-1)
        return
    c = 1
    for i in range(N):
        if a[i] == c:
            c += 1
    print(N-c+1)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(N)]  
    solve(N, a)

if __name__ == '__main__':
    main()

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

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

print(b if b<n else -1)

Solution (Python):
N = int(input())
M = [int(i) for i in input().split(" ")]
m = sorted(M)
count = 0
min = 1
if m[0]!=1:
  print(-1)
else:
  for j in range(N):
    if M[j]==min:
      min+=1
    else:
      count+=1
      M[j]=0
  print(count)

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

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

if ng == 1:
    ans = -1

print(ans)

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

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

if N - cnt == num-1 and 1 in a:
  print(cnt)
else:
  print(-1)

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

Solution (Python):
renga=int(input())
number=list(map(int,input().split()))
count,num = 0,1
for i in number:
  if num == i:
    num += 1
  else:
    count += 1
if count == renga:
  print(-1)
else:
  print(count)

Solution (Python):
import numpy as np
n = int(input())
a = np.array(input().split(),dtype=int)

now = 1
bre = 0

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

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

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

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

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

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

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n = int(input())
aaa = get_nums_l()

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

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

count = 0

for i in a_List:
    if i == count + 1:
        count += 1

ans = N - count

print(ans if count != 0 else -1)

Solution (Python):

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

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

Solution (Python):
def main():
    n=int(input())
    aa=list(map(int,input().split()))
    b=0
    i=1
    while True:
        try:
            j=aa.index(i,b)
        except ValueError:
            break
        b=j+1
        i+=1
    if i<=1:
        print(-1)
    else:
        print(n-i+1)

main()

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

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


if __name__ == '__main__':
    main()

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

count = 0
num = 1
for i in range(0,n):
  if block[i] == num:
    num += 1
  else:
    count += 1

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

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

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


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

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

cur=1
count=0
for i in range(n):
  if v[i]!=cur:
    count+=1
  else:
    cur+=1
if count==n:
  print(-1)
else:
  print(count)

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


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

Solution (Python):
t = int(input())
n = [ int(i) for i in input().split(" ") ]
 
count = 0
num = 1

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

if count == t:
  count = -1

print(count)

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

Solution (Python):
from numpy import *

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

count = 0

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

ans = N - count

if count == 0:
    ans = -1

print(ans)

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

cnt = 1
for now_a in a:
    if cnt == now_a:
        cnt += 1

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

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

cnt = 1
for now_a in a:
    if cnt == now_a:
        cnt += 1

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

Solution (Python):

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

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

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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

index = 1
co = 0
for i in range(len(A)):
	if A[i] == index:
		index += 1
	else:
		continue

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

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

flg = False
nextval = 1
br = 0
for idx, a in enumerate(li_a):
    if a == nextval:
        nextval += 1
        flg = True
    else:
        br += 1
if flg:
    print(br)
else:
    print('-1')

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

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

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

A = []
i = 1
j = 0
while j != N:
    if a[j] == i:
        i += 1
    j += 1
else:
    if i == 1:
        print(-1)
    else:
        print(N-(i-1))

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

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

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

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

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

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

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


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


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def main():
    
    N = Scanner.int()
    A = Scanner.map_int()
    now = 1
    ans = 0
    for i in range(N):
        if now == A[i]:
            now += 1
        else:
            ans += 1
    ans = ans if ans != N else -1
    print(ans)

    return


if __name__ == "__main__":
    main()

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

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

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

x = 1
ans = 0
flag = False
for a in A:
    if a == x:
        x += 1
        flag = True
    else:
        ans += 1
if flag:
    print(ans)
else:
    print("-1")

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

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

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

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

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

if b_num == n:
    b_num = -1

print(b_num)

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

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

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

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

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

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

Solution (Python):

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

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

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

if not 1 in a:
    print(-1)
else:
    p = a.index(1)
    target = 2

    for i in range(p, N):
        if a[i]==target:
            target += 1
    
    print(N-target+1)

Solution (Python):
N = int(input())
n_list = input().split(' ')
sort_list = []
t = 1
for num in n_list:
  if int(num) == t:
    sort_list.append(t)
    t += 1
if len(sort_list) == 0:
  print(-1)
else:
  print(N - len(sort_list))

Solution (Python):
from sys import stdin, stdout
N = int(stdin.readline())
brick = list(map(int, stdin.readline().split()))

cont = 0
for i in range(N):
    if brick[i] == cont+1:
        cont = cont+1

if cont == 0:
    stdout.write("-1\n")
else:
    stdout.write("%d\n" % (N-cont))

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

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

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

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

ans = 0
for i in aa:
	if ans + 1 == i:
		ans+=1
if 0 == ans:
	print(-1)
else:print(N-ans)

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

Solution (Python):
N = int(input())
num_list = list(map(int,input().split()))
num = 1
for i in num_list:
	if i == num:
		num+=1
if num == 1:
	print(-1)
else:
	print(N - num + 1)

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

c = -1
b = 1
ans = 0
for i in a:
    if b == i:
        if i == 1:
            c = 1
        b += 1
    else:
        ans += 1

if c == -1:
    ans = -1

print(ans)

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

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

print(-1)

Solution (Python):
n=int(input())
tmp=[int(x) for x in input().split()]
cnt=0
num = []
i = 0
for j in range(n):
  if i+1 == tmp[j]:
    num.append(tmp[j])
    i+=1
  else:
    cnt+=1

print(cnt if num!=[] else -1)

Solution (Python):
N=int(input())
L=list(map(int,input().split()))
ANS=0
FLG=-1
CNT=1
for i in L:
  if i == CNT:
    FLG=0
    CNT+=1
  else:
    ANS+=1
if FLG != -1:
  print(ANS)
else:
  print(-1)