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 sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

N = I()
A = LI()

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

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

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

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

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

print(N - p + 1 if 1 in A else -1)

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

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

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

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

Solution (Python):
n=int(input())
lists=list(map(int,input().split()))
counter=1
for i in range(n):
    if lists[i]==counter:
        counter+=1

p=n+1-counter
if p==n:
    print(-1)
else:
    print(p)

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

    for a in A:
        if rec[-1] + 1 == a:
            rec.append(a)

    if rec == [0]:
        print(-1)
    else:
        print(len(A) - len(rec[1:]))


if __name__ == '__main__':
    main()

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

if 1 not in A:
  print(-1)
else:
  ans,now,i=0,1,0
  while i<n:
    if A[i]==now:
      now+=1
    else:
      ans+=1
    i+=1
  print(ans)

Solution (Python):
N, *A = map(int, open(0).read().split())

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

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

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

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

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

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

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

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

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

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

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

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

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

A = list(map(int, input().split()))
pointa = 1
flag = False
for i in range(N):
    if A[i] == pointa:
        flag = True
        pointa += 1

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

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

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

Solution (Python):
def main():

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



            

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
a = [int(c) for c in input().split()]
m = 1
ans = 0
flag = True
for i in range(N):
  c = a[i]
  if c==m:
    m += 1
    flag = False
    continue
  ans += 1
if flag:
  print(-1)
else:
  print(ans)

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

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

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

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

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

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

i = 1
K = 0
for a in A:
    if a == i:
        K += 1
        i += 1

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

Solution (Python):
import copy
import heapq
import math
import fractions

def j(n):
    if n:print("Yes")
    else:print("No")
    exit(0)
rem = 10 ** 9 + 7

"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def ipmultiplerow(n):
    a = []
    for i in range(n):
        a.append(ip())
    return a
def printrow(a):
    for i in a:
        print(i)


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

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

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

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

if ret == N:
  ret = -1

print(ret)

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    t = 1
    flag = 0
    for sa in a:
        if sa == t:
            flag = 1
            t += 1
    if flag == 0:
        return -1
    else:
        t -= 1
        return n - t


print(main())

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

now = 1
ans = 0

for aa in a:
    
    if aa != now:
        ans += 1
    else:
        now = aa + 1

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

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


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

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

Solution (Python):
def main():

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

    if 1 not in a: return -1
    ans = 0
    p = 1
    for i in range(N):
        if a[i] != p:
            ans += 1
        else:
            p += 1
    return ans


if __name__ == '__main__':
    print(main())

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

Solution (Python):
def main():
    n = input()
    aa = map(int, raw_input().split())
    count = 0
    b = 1
    for a in aa:
        if a != b:
            count += 1
        else:
            b += 1
    if n == count:
        print -1
    else:
        print count

main()

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(1000000000)
from fractions import gcd
from itertools import count
from functools import lru_cache
from collections import defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok


def main():
    N = ii()
    A = lmis()
    i = 1
    for a in A:
        if i == a:
            i += 1
    i -= 1
    if i == 0:
        print(-1)
    else:
        print(N - i)

main()

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

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

Solution (Python):


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

Solution (Python):
n = int(input())
arr = list(map(int, input().split(' ')))
cc = 1
ans = 0
for num in arr:
    if num == cc:
        cc += 1
    else:
        ans += 1

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

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

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

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
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 ans==n:
    print(-1)
else:
    print(ans)

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

current = 1
crashed = 0
for a in As:
    if a == current:
        current += 1
    else:
        crashed += 1
if current == 1:
    print(-1)
else:
    print(crashed)

Solution (Python):

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

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

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

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

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

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

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

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

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

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

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

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

flag = False
answer = 0
count = 1
for i in a:
    if i == count:
        flag = True
        count += 1
    else:
        answer += 1

if flag:
    print(answer)
else:
    print(-1)

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
if 1 not in a:
    print(-1)
    exit()

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


print(n-now+1)

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

cur = 1
for x in nums:
    if x == cur:
        cur += 1

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

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


main()

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

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

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

Solution (Python):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
A = many_int()

count=0
index=1
for a in A:
    if a!=index:
        count+=1
    else:
        index += 1

if len(A) == count:
    print(-1)
else:
    print(count)

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


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def main():
    N = int(input())
    A = read_list()

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

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


if __name__ == "__main__":
    main()

Solution (Python):
from bisect import bisect_left

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

L = [A[0]]
for a in A[1:]:
    if a > L[-1]:
        
        L.append(a)
    else:
        
        
        L[bisect_left(L, a)] = a

ret = N + 1
for cnt, l_ in enumerate(L, 1):
    if l_ != cnt:
        break
    ret = cnt

print(N - ret)

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

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

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

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

Solution (Python):
from fractions import gcd

from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7



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

    
    

        


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	N = INT()
	A = MAP()

	cur = 1
	cnt = []
	for i in range(N):
		
		if A[i] == cur:
			cnt.append(i)
			cur += 1

	
	
	print(N-len(cnt) if len(cnt)>0 else -1)

if __name__ == '__main__':
	main()

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]

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

if __name__ == "__main__":
    solve()

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

Solution (Python):

def solve():
    N=int(input())
    AL=list(map(int,input().split()))
    now=1
    broken=0
    
    for a in AL:
        if a==now:
            now+=1
        else:
            broken+=1
        
    if 1 not in AL:
        return -1
    
    return broken

print(solve())

Solution (Python):
import sys
n = int(input())
a_ls = [int(i) for i in sys.stdin.readline().split()]
cur = 1
for a in a_ls:
    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()))
cur = 0
for i in range(N):
  if A[i] == cur + 1:
    cur += 1
print(N-cur if cur != 0 else -1)

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

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

Solution (Python):


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

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

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

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

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

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

f=1 in a
if f:
    ans=0
    i=1;j=0
    while j<N:
        if a[j]==i:
            i+=1
            j+=1
        else:
            ans+=1
            j+=1

print(ans if f else -1)

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

pos = 1
get = 0
for a in al:
    if pos == a:
        get += 1
        pos += 1
if get == 0:
    print(-1)
else:
    print(n-get)

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

Solution (Python):
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)

Solution (Python):
import sys
import math
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()

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

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

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

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

Solution (Python):
N = int(input().strip())
B = map(int, input().strip().split(' '))

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

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

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

count = 1

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

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

print(n - count + 1)

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

temp = 1
ans = 0
for x in a:
    if x != temp:
        ans += 1
    else:
        temp += 1

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

Solution (Python):
n=int(input())
al=list(map(int,input().split()))
ans=0
now=1
for a in al:
    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()))
x,r=1,0
for a in A:
    if a==x:
        x+=1
    else:
        r+=1
print(-1 if r==N else r)

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

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

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

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

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

Solution (Python):
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(-1)
else:
    print(n - count)

Solution (Python):

import sys
input = sys.stdin.readline

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

cur = 1
kudaku = 0
for i in a:
    if i == cur:
        cur+=1
    else:
        kudaku+=1
if kudaku==n:
    kudaku = -1
print(kudaku)

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

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

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    aa=LI()
    cnt=1
    for a in aa:
        if cnt==a:
            cnt+=1
    if cnt==1:
        print(-1)
    else:
        print(n-cnt+1)
main()

Solution (Python):
def inpl():
    return list(map(int, input().split()))


N = int(input())
A = inpl()

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

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

Solution (Python):

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

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

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

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

Solution (Python):
def p_d():
    n = int(input())
    A = map(int, input().split())
    st = 1
    ans = n
    for a in A:
        if a == st:
            st += 1
            ans -= 1
    print(ans if n != ans else -1)
    
p_d()

Solution (Python):
def examA():
    AB = [I() for _ in range(2)]
    for i in range(1,4):
        if not i in AB:
            ans = i
            break
    print(ans)
    return

def examB():
    N = I()
    S,T = LSI()
    ans = ""
    for i in range(N):
        ans += S[i]+T[i]
    print(ans)
    return

def gcd(x, y):
    if y == 0:
        return x
    while y != 0:
        x, y = y, x % y
    return x
def lcm(x, y):
    return x * y // gcd(x, y)
def examC():
    A, B = LI()
    ans = lcm(A,B)
    print(ans)
    return

def examD():
    N = I()
    A = LI()
    ans = N; cur = 1
    for a in A:
        if cur==a:
            ans -=1
            cur +=1
    if ans==N:
        ans = -1
    print(ans)
    return

def examE():
    return

def examF():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examD()

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

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

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

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

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

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

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

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

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

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

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

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

c = 1
for i in range(N):
    if A[i]==c:
        c += 1
        continue
    broken += 1

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
cnt=1
for i in a:
  if i==cnt:
    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
c = 1
for i in range(n):
    if c == a[i]:
        c += 1

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

print(ans)

Solution (Python):






from sys import stdin,setrecursionlimit









from fractions import gcd
setrecursionlimit(10**6)
input=stdin.readline

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

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

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

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

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

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

now=1

for i in range(n):
    if alist[i]==now:
        now+=1

if now!=1:
    print(n-now+1)
else:
    print(-1)

Solution (Python):
from math import isinf

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

ans = float('inf')
broke = 0
cur = 0
for i, a in enumerate(A):
    if a == cur + 1:
        cur += 1
        ans = min(ans, broke + N - i - 1)
    else:
        broke += 1
if isinf(ans):
    print(-1)
else:
    print(ans)

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

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

Solution (Python):

import sys
input = sys.stdin.buffer.readline


from collections import defaultdict


def getlist():
	return list(map(int, input().split()))


def main():
	N = int(input())
	a = getlist()
	val = 1
	for i in range(N):
		if a[i] == val:
			val += 1
	if val == 1:
		print(-1)
	else:
		print(N - val + 1)
	


if __name__ == '__main__':
	main()

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
aa = inpl()

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

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

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

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

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

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

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

n = onem()

a = l()

c = 0

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