Problem:
 Score : 400 points    Problem Statement We have N bricks arranged in a row from left to right.  The i -th brick from the left (1 \leq i \leq N) has an integer a_i written on it.  Among them, you can break at most N-1 bricks of your choice.  Let us say there are K bricks remaining. Snuke will be satisfied if, for each integer i  (1 \leq i \leq K) , the i -th of those brick from the left has the integer i written on it.  Find the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.      Constraints  All values in input are integers.  1 \leq N \leq 200000  1 \leq a_i \leq N         Input Input is given from Standard Input in the following format:  N  a_1  a_2  ...  a_N       Output Print the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.        Sample Input 1 3
2 1 2      Sample Output 1 1  If we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.       Sample Input 2 3
2 2 2      Sample Output 2 -1  In this case, there is no way to break some of the bricks to satisfy Snuke's desire.       Sample Input 3 10
3 1 4 1 5 9 2 6 5 3      Sample Output 3 7       Sample Input 4 1
1      Sample Output 4 0  There may be no need to break the bricks at all.

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

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

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

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

Solution (Python):

import sys
input=sys.stdin.readline

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


    for x in numbers:
        if x ==n:
            n+=1


    answer = N - n +1

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

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

if __name__=="__main__":
    main2()

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

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

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

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

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

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

count=0
z=True
j=0

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

    print(n-count)

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

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

print(ans)

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

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

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

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

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

    

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

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

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

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

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

Solution (Python):


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

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

    if flg:
        ans = N - tmp + 1

    print(ans)

if __name__ == "__main__":
    main()

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

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    a = i_list()

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


if __name__=="__main__":
    main()

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

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

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

Solution (Python):
def abc148d_brick_break():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = 0
    val = 1
    for item in a:
        if item == val:
            val += 1
        else:
            cnt += 1
    if val == 1:
        print('-1')
    else:
        print(cnt)
abc148d_brick_break()

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    if 1 not in A:
        print(-1)
        exit()
    next = 1
    for a in A:
        if a == next:
            next += 1
    print(N - next + 1)


if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):

import sys
from itertools import chain


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

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


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


if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    lst = LI()
    cnt = 1
    ans = 0

    for brock in lst:
        if brock == cnt:
            cnt += 1
        else:
            ans += 1

    if cnt != 1:
        print(ans)
    else:
        print(-1)
    
main()

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

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

ans=0
j=1
for i in s:
    if i!=j :
        ans+=1
    else:
        j+=1
print(ans) if ans<n else print(-1)

Solution (Python):
N=int(input())
A=list(map(int, input().split()))[::-1]

flag=0
i=0
now=1
cnt=0
ans=0

if 1 not in A:
	print(-1)
	
else:
	while flag==0:
		if A[-(i+1)]!=now:
			A.pop(-(i+1))
			cnt+=1
			ans+=1
		else:
			i+=1
			cnt+=1
			now+=1
		
		if cnt==N:
			flag=1
	
	print(ans)

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

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

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

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

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

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

Solution (Python):



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

targetnum=1
breaknum=0

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

Solution (Python):

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

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

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

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

Solution (Python):


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

K=1
dest=0
for a in A:
    if a==K:
        K+=1
    else:
        dest+=1
print(dest if K>1 else -1)

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

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

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

print(N-cnt)

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

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

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

print(N-len(l))

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

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

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

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

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

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

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

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

ans = 1
cnt = 0

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

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

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

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

Solution (Python):
import os
import heapq
import sys,threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10**5)
from io import BytesIO, IOBase
def gcd(a,b):
    if b==0:

        return a
    else:
        return gcd(b,a%b)
def power(x, p,m):
    res = 1
    while p:
        if p & 1:
            res = (res * x) % m
        x = (x * x) % m
        p >>= 1
    return res
def inar():
    return [int(k) for k in input().split()]

def lcm(num1,num2):
    return (num1*num2)//gcd(num1,num2)

def main():
    n=int(input())
    arr=inar()
    count=1
    for i in range(n):
        if arr[i]==count:
            count+=1
    
    if count==1:
        print(-1)
    else:
        print(n-count+1)






BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()

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

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

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

def main():
    mod=10**9+7
    N=I()
    A=LI()
    cnt=0
    now=1
    
    for i in range(N):
        if A[i]==now:
            now+=1
        else:
            cnt+=1
            
    if cnt==N:
        cnt=-1
    print(cnt)
        

main()

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

ans = 0
if 1 not in a:
  print(-1)
  sys.exit()
  
index = 1
for i in a:
  if i != index:
    ans+=1
  else:
    index+=1
    
print(ans)

Solution (Python):
import math
import statistics
a=int(input())





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




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

Solution (Python):

"""
Created on Wed Sep  9 01:08:27 2020

@author: liang
"""

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

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

Solution (Python):
import sys

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


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

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

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

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

cnt = 0

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

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

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

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

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

Solution (Python):

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


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


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


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


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


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


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

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

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


def main():
    solve()


if __name__ == '__main__':
    main()

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

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

Solution (Python):
N = int(input())
blocks = list(map(int, input().split()))
target = 1
for block in blocks:
  if block == target:
    target += 1
if target > 1:
  print(N-target+1)
else:
  print(-1)

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

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

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

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

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

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

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

k = 0

for v in a:
    if v == k+1:
        k += 1

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

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

if __name__ == "__main__":
    solve()

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

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

cnt=0
m=1

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

Solution (Python):






N = int(input())



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





































num = 1
for i in A:
    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()))
x=0
temp=1
f=False
for i in range(n):
    if a[i]==temp:
        f=True
        temp+=1
    else:
        x+=1
if f:
    print (x)
else:
    print (-1)

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

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

if __name__ == "__main__":
    main()

Solution (Python):

import sys
def input():
    return sys.stdin.readline()[:-1]

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

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

if __name__ == '__main__':
    main()

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

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

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

now = 1

c = 0

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

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

Solution (Python):
def main():
    n = int(input())
    a_list = list(map(int, input().split()))

    num = 1
    for a in a_list:
        if a == num:
            num += 1
    
    if num == 1:
        print(-1)
    else:
        print(n - num + 1)


if __name__ == "__main__":
    main()

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

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

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

if __name__ == '__main__':
    main()

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

Solution (Python):
from collections import deque
N = int(input())
Query = deque(map(int,input().split()))
ju = 1
Answer = 0
for i in range(N):
    q = Query.popleft()
    if q == ju:
        ju +=1
    else:
        Answer += 1
if ju == 1:
    Answer = -1
print(Answer)

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

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
ans=[0]

cnt=0
hit=0
while cnt<N:
  if ans[hit]+1==A[cnt]:
    hit+=1
    ans.append(hit)
  cnt+=1
print(N-len(ans[1:]) if len(ans)>1 else -1)

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

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

Solution (Python):









import os
import sys




def main():
    N = int(input())
    A = list(map(int, input().split()))
    if not 1 in A:
        print(-1)
        return
    index = 0
    for a in A:
        if index+1 == a:
            index += 1
    print(N-index)


if __name__ == "__main__":
    main()

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
x = 1
list1 = []

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

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

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

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

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

main()

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

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

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

i = i-1

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

Solution (Python):


from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def solve(N: int, a: "List[int]"):
    c = 1
    for i in a:
        c += i == c
    return len(a) - (c-1) if c != 1 else -1


def main():

    sys.setrecursionlimit(10 ** 6)

    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)]  
    print(f'{solve(N, a)}')


if __name__ == '__main__':
    main()

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1 not in a_lst:
        count = -1

    print(count)


if __name__ == '__main__':
    main()

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()))
from collections import deque
a = deque(a)
ans = 0
now = 1
while a:
  x = a.popleft()
  if x == now:
    now += 1
  else:
    ans += 1
if ans == N:
  ans = -1
print(ans)

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

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

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

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

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

i=0
ans=0
saigo=0
k=1
kosuu=n

while i<=n-1:
    if a[i]!=k:
        ans+=1
        kosuu-=1
    else:
        saigo=a[i]
        k+=1
    i+=1

if kosuu==0:
    print(-1)
    exit()

if kosuu==saigo:
    print(ans)
else:
    print(-1)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
from collections import deque
q = deque(A)
i = 1
ans = []
while i <= n and q:
    a = q.popleft()
    if a==i:
        ans.append(a)
        i += 1
if len(ans)==0:
    print(-1)
else:
    print(n-len(ans))

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

card=1
cnt=0

for i in a:
  if i==card:
    card+=1
  else:
    cnt+=1

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

else:
  print(cnt)

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