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 = [int(s) - 1 for s in input().split()]

result = 0
for i in range(N):
    if a[i] != (i - result):
        result += 1

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

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

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

ans = -1 if x == 0 else n - x
print(ans)

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

k=1
cnt=0
for i in range(n):
  if A[i]!=k:
    cnt+=1
  else:
    k+=1
if cnt==n:
  print(-1)
else:
  print(cnt)

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

N = 0
C = 1

for num in B:
  if num == C:
    C += 1
    N += 1

ANSWER = 0

if N == 0:
  ANSWER = -1
else:
  ANSWER = A - N
  
print(ANSWER)

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

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
left = 0
num = 1
start = 0
while True:
    Flag = True
    for i in range(start,n):
        if a[i] == num:
            left += 1
            start = i
            Flag = False
            num += 1
            break
    if Flag:
        break
if left == 0:
    ans = -1
else:
    ans = n - left
print(ans)

Solution (Python):

N = int(input())
Alist = list(map(int, input().split()))
if min(Alist) != 1:
    print(-1)
else:
    max_num = 1
    i = 0
    while i < N:
        a = Alist[i]
        if a == max_num:
            max_num += 1
        i += 1
    print(N - max_num + 1)

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


n=1

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

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

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

print(N-focus+1 if focus > 1 else -1)

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

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

Solution (Python):
import sys

def main():

    

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

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

   
    if r == n:
        print(-1)
    else:
        print(r)
            
if __name__ == '__main__':
    main()

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

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

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

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

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

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

c = 1
res = 0

for num in a:
    if num == c:
        c += 1
    else:
        res += 1

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

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

Solution (Python):

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


import numpy as np
import bisect as bi

a = np.array(a)


warm = 1

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

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

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

current = 1
break_count = 0
for i in range(len(A)):
  if A[i] != current:
    break_count += 1
  else:
    current += 1

ans = break_count if current > 1 else -1
print(ans)

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

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

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

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

for i in a:
  if i==b:
    b+=1
  else:
    ans+=1
print(ans)

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

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

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
b = 0
c = 1
for a in A:
    if a == c:
        b += 1
        c += 1

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

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

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

if search == 1:
    print(-1)
else:
    print(len(a) - search + 1)

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

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

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

Solution (Python):


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

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

Solution (Python):
n = input().split()
aList = [int(_) for _ in input().split()]

count = 1
for a in aList:
  if count == a:
    count += 1
if count == 1:
  print('-1')
else:
  result = len(aList) - count + 1
  print(result)

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

Solution (Python):
from sys import stdin
n = int(stdin.readline())
bricks = [int(x) for x in stdin.readline().split()]
if 1 not in bricks:
    ans = -1
else:
    counter = 1
    ans = 0
    for i in range(n):
        if bricks[i] == counter:
            counter += 1
        else:
            ans += 1
print(ans)

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

i = 1
count = 0
bool = "False"
for n in a:
  if n == i:
    i += 1
    bool = "True"
  else:
    count += 1

if bool == "False":
  print("-1")
else:
	print(count)

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

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

count = 1
break_count = 0

for i in range(N):
    if a_list[i] == count:
        count += 1
    else:
        break_count += 1
    
if break_count == N:
    print(-1)
else:
    print(break_count)

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
n, ans = 0, 0
for a in A:
    if a == n+1:
        n += 1
    else:
        ans += 1
if ans == len(A):
    print(-1)
else:
    print(ans)

Solution (Python):
if __name__=='__main__':
    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:
        count=-1
    print(count)

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

x = 1
for a in map(int, input().split()):
    if a == x:
        x += 1

if x == 1:
    result = -1
else:
    result = N - (x - 1)

print(result)

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

Solution (Python):

N = int(input())

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

ans = 0

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

ci = 1
for i in range(1, N+1):
    if nums[i-1] == ci:
        ci += 1
    else:
        ans += 1
print(ans)

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

Solution (Python):

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

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

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

Solution (Python):



def main():
    n = int(input())
    a = list(map(int, input().split()))
    count = 0
    number = 1

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

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


if __name__ == '__main__':
    main()

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

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

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

print(N-c+1 if c!=1 else -1)

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

Solution (Python):
quantity = int(input())
block = list(map(int,input().rstrip().split(" ")))

num = 1
for i in block:
    if i == num:
        num += 1

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

Solution (Python):
def answer(n, A):
  block=0
  count=1
  for a in A:
    if a != count:
      block += 1
    else:
      count += 1
  if block == len(A):
    return -1
  return block

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

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

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

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

Solution (Python):
def solve(string):
    n, *a = map(int, string.split())
    c = 1
    for _a in a:
        if c == _a:
            c += 1
    return str(-1 if c == 1 else n - c + 1)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

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

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

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

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

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

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

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

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

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

Solution (Python):
n = int(input())
a_l = list(map(int, input().split()))
ans,left = 0,1
for a in a_l:
    if a==left:
        left +=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()]

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

print(ans)

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

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

print(ans)

Solution (Python):
N = input()
nums = list(map(int,input().split()))
index , pre= 0,0
max_num = 1
ans = 0
if not max_num in nums:
  print(-1)
  exit()
while 1:
  for i,n in enumerate(nums):
    if i < index:
      continue
    if n == max_num:
      index=i
      max_num+=1
      ans+=1
  if index == pre:
    if ans == 0:
      print(ans)
    else:
      print(len(nums)-ans)
    break
  pre=index

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


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

now = 0
for x in a:
    if x == now + 1:
        now = x

if now:
    print(n-now)
else:
    print(-1)

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

count = 1
i = 0

tmp = 0
while i < N:
  if count == A[i]:
    tmp += 1
    count += 1
  i += 1

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

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

ans_inv,i = 1,0

while True:
    if i == n:
        break
    if list1[i] == ans_inv:
        ans_inv += 1
    i += 1
if ans_inv == 1:
    print(-1)
else:
    print(n - (ans_inv-1))

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

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

Solution (Python):
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista

def brick(): 
    N = wczytaj_liste()[0]
    lista_cegiel = wczytaj_liste()
    odp = 0 
    n = 1
    for cegla in lista_cegiel: 
        if cegla == n: 
            n += 1 
        else: 
            odp +=1 
    if odp < N: 
        print(odp)
    else: 
        print('-1')

brick()

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

target = 1
ans = 0
for x in arr:
    if x == target:
        ans += 1
        target += 1
print(-1 if ans == 0 else n-ans)

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

next = 1
ans = 0

for i in range(n):
    if next == renga[i]:
        next += 1
    else:
        ans += 1
if ans == n:
    ans = -1
print(ans)

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
b_count = 0
s_count = 1

for i in range(n):
  
  if l[i] == s_count:
    s_count += 1
  else:
    b_count += 1

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

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

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

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

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

for a in a_n:
    if nxt == a:
        nxt += 1
    else:
        ans += 1

if ans == n:
    ans = -1

print(ans)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
ans = 0
cnt = 1
for x in a:
  if x == 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()))
k=1
count=0
while True:
    for n in range(0,N):
        if a[n]!=k:
            count+=1
        elif a[n]==k:
            k+=1
        elif a[n]==a[N-1]:
            break
    if k==1:
        print("-1")
        break
    else:
        print(count)
        break

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

i = 1
ans = 0

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

if 1 not in A:
    ans = -1
        
print(ans)

Solution (Python):
n = int(input())
box = []
box.append(list(map(int, input().split())))
box1 = box[0]  
tibi = min(box1)
ans = 0


if tibi!=1:
  print(-1)
else:
  num = 0
  for i in range(len(box1)):
    if box1[i]==(num+1):
      num += 1
      continue
    else:
      ans += 1
  print(ans)

Solution (Python):
def func1(lst, value):
    return [i for i, x in enumerate(lst) if x == value]

n = int(input())
box = []
box.append(list(map(int, input().split())))
box1 = box[0]  
tibi = min(box1)
ans = 0


if tibi!=1:
  print(-1)
else:  
  num = 0
  for i in range(len(box1)):
    if box1[i]==(num+1):
      num += 1
      continue
    else:
      ans += 1
  print(ans)

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

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

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

ans = 0
now = 1
flag = False

for i in a:
    if i == now:
        flag = True
        now += 1
    else:
        ans += 1
        
print(ans if flag else -1)

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

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

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

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

if len(set(a)) == 1:
    if list(set(a))[0] != 1:
        print(-1)
        exit()
    elif len(a) == n:
        pass
    else:
        print(0)
        exit()


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

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

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

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
counter = {i:[] for i in range(1,n+1)}
for i in range(n):
  counter[a[i]].append(i)


ans = 0
tmp = -1
for i in range(1,n+1):
  if counter[i] == []:
    break
  for c in counter[i]:
    if tmp < c:
      tmp = c
      ans += 1
      break
  else:
    break

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

Solution (Python):
n = int(input())
lst = list(map(int, input().split()))
i = 1
for j in lst:
    if i == j:
        i += 1

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

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

t = 1
result = 0
for a in map(int, input().split()):
    if a == t:
        t += 1
    else:
        result += 1

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
if n == 1:
	if a[0] == 1:
		print (0)
		exit()
	else:
		print (-1)
		exit()
b = set(a)
if len(b) == 1 and a[0] != 1:
	print (-1)
	exit()

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

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
count = 0
k=0
t=0

while t<len(A):
    if A[t] == k+1:
            k += 1
            t += 1
    else:
            count += 1
            t += 1
if count == N:
    print(-1)
else:
    print(count)

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

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

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

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

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

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

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

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

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

if j == 1:
    print(-1)

else:
    print(n - j + 1)

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

Solution (Python):
n = int(input())
lst = map(int, input().split())
ans = 0
start = 1
for i in lst:
    if i == start:
        start += 1
        ans += 1
if ans == 0:
    print(-1)
else:
    print(min(n - 1, n - ans))

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

Solution (Python):

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

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

Solution (Python):
N = int(input())
A = map(int, input().split())
count = 0
num = 1
for a in A:
    if a == num:
        num += 1
    else:
        count += 1

print(-1 if num == 1 else count)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
count = 0
num = 1
for a in A:
    if a == num:
        num += 1
    else:
        count += 1

print(-1 if num == 1 else count)

Solution (Python):

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

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

cnt=0
a=1
for i in s:
	if a!=i:
		cnt+=1
	if a==i:
		a+=1
if a==1:
	print("-1")
if a!=1:          
	print(cnt)

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

count = 0

i = 1
k = 1
index = 0


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

if index != 0 or (n == 1 and a[0] == 1) or (index == 0 and count == 1):
    print(n-count)
else:
    print("-1")

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    want = 1
    cnt = 0
    for a in A:
        if a == want:
            want += 1
        else:
            cnt += 1
    if want == 1:
        cnt = -1
    print(cnt)

main()

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

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

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

Solution (Python):

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

Solution (Python):

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

if cnt == 0 :
    cnt = n + 1
print(n - cnt)

Solution (Python):
from collections import deque

n = int(input())
a_list = deque(map(int, input().split()))

p = 1
ans = 0
while len(a_list) > 0:
    if a_list.popleft() == p:
        p += 1
    else:
        ans += 1
if ans == n:
    ans = -1
print(ans)

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

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

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

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

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

Solution (Python):

from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


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


def LF(): return list(map(float, input().split()))


def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def LS(): return list(map(list, input().split()))


def S(): return list(input().rstrip())


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


mod = 1000000007
inf = 1e10




def solve():
    n = II()
    a = LI()
    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)
    return



if __name__ == '__main__':
    solve()

Solution (Python):
n = int(input())
l = input()
l = l.split()
l = list(map(int,l))
p = 1
d = 0
for i in l:
    if p == i:
        pass
        p+=1
    else:
        d+=1
if d == n:
    print("-1")
else:
    print(d)

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

for i in range(n):
    if a[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()))
tmp = 1
ans = 0
for i in range(N):
    if A[i] == tmp:
        tmp +=1
    else:
        ans += 1
if N == ans:
    print(-1)
    exit()
print(ans)

Solution (Python):


N = int(input())
nums = input().split()

hitting = 1
for num in nums:
    if num == str(hitting):
        hitting += 1

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

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

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

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

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

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

Solution (Python):


N = int(input())
nums = list(map(int, input().split()))
 
hitting = 1
isHitOnce = False
for num in nums:
    if num == hitting:
        hitting += 1
        isHitOnce = True
 
if hitting == 1:
    print(-1)
else:
    print(N - (hitting - 1))

Solution (Python):


from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n = ii()
    a = li()

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

    
main()

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