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):
'''AtCoder水色になりたいのよさ
一番左を「1」にするために、「num」の初期値を1にし、
配列aを順番に判定していきます。
1以外のブロックは壊して「b_num」に足していきます。
1が見つかった後は、「num」を1増やして、同じ処理を続けます。
結果的に壊したブロックの数「b_num」が答えになります。
'''
n = int(input())
a = list(map(int, input().split()))
num = 1
b_num = 0

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

if b_num == n:
    b_num = -1

print(b_num)

Solution (Python):
'''ika tako
先頭から貪欲に残せる要素を拾っていって、
残る要素数を  N  から引いた値が答え
'''
n = int(input())
aaa = list(map(int, input().split()))
 
if 1 not in aaa:
    print(-1)
    exit()
 
i = 0
a = 1
while True:
    try:
        j = aaa.index(a, i)
        
    except ValueError:
        break
    i = j + 1
    a += 1
 
print(n - a + 1)

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

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

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

Solution (Python):


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

flag=False
cnt=1
for i in range(n):
    if a[i]==cnt:
        cnt+=1
        flag=True

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

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

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

for e in a:
  if e == cur:
    cur += 1
  else:
    ans += 1
print(ans)

Solution (Python):
from collections import deque
n = int(input())
a = list(map(int, input().split()))
serch_value = 1
for v in a:
    if (v == serch_value):
        serch_value += 1
found_value = serch_value - 1
if (found_value == 0):
    print(-1)
else:
    print(n-found_value)

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

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

    target = 1
    for i in range(n):
        if a[i] == target:
            target += 1
    if target == 1:
        print(-1)
        sys.exit(0)

    print(len(a) - (target - 1))

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

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

print(N-cnt if cnt != 0 else -1)

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

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

out = 0
num = 1
for A in As:
    if  A == num:
        num += 1
    else:
        out += 1
if out == n:
    print(-1)
else:
    print(out)

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

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

if ans == n:
    ans = -1

print(ans)

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

Solution (Python):

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

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

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


n = int(input())
a = list(map(int, input().split()))
i = 1
bricks = 0

for ai in a:
	if ai == i:
		bricks += 1
		i += 1

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

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
        a[i] = 0
    else:
        c += 1
if ans < n:
    print(ans)
else:
    print(-1)

Solution (Python):
from collections import deque
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    num = 0

    
    for i in range(N):
        if num > N - 1:
            print(-1)
            exit()
        elif A[i] == num+1:
            num += 1
    if num == 0:
        print(-1)
    else:
        print(N-num)


if __name__ == '__main__':
    solve()

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

break_cnt = 0
find_num = 1

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

if find_num == 1:
    print(-1)
else:
    print(break_cnt)

Solution (Python):
from collections import deque
N = int(input())
a = list(map(int,input().split()))
a = deque(a)
count = 0
k = 1
for i in range(N):
    if a[0] != k:
        a.popleft()
        count += 1
    else:
        a.popleft()
        k += 1
if k == 1:
    print(-1)
else:
    print(count)

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

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

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

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

Solution (Python):
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
A = rl()

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

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

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

Solution (Python):

import sys


def solve(N: int, a: "List[int]"):
    num_break = 0
    n = 1
    for a_ in a:
        if a_ == n:
            n+=1
        else:
            num_break+=1
    if n > 1:
        print(num_break)
    else:
        print(-1)

    return



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

if __name__ == '__main__':
    main()

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    n = int(input())
    A = readInts()
    now = 1
    i = 0
    cnt = 0
    while i < n:
        if A[i] == now:
            now += 1
        else:
            cnt += 1
        i += 1
    if cnt == n:
        print('-1')
    else:
        print(cnt)
if __name__ == '__main__':
  main()

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

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

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

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

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

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

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

if __name__ == '__main__':
    main()

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

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

Solution (Python):
n = int(input())
lis = list(map(int, input().split()))
res = 0
cnt = 0
flg = False
for i in lis:
    if i == 1:
        flg = True
        res = max(res, cnt)
        cnt = 1
    elif i == cnt + 1:
        cnt += 1

if not flg:
    print(-1)
else:
    print(n - max(res, 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()))

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

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

current = 1
ans = 0
if not 1 in aes:
  print(-1)
else:
  for a in aes:
    if a == current:
      current += 1
    else:
      ans += 1

  print(ans)

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

if 1 in a:
    i = a.index(1)
    now = 1
    while i < n:
        if a[i] == now + 1:
            now += 1
        i += 1
    print(n - now)
else:
    print(-1)

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

idx = 1
chop = 0
for n in range(N):
    if As[n] == idx:
        idx += 1
    else:
        chop += 1


if chop == N:
    print('-1')
else:
    print(chop)

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

num_looking_for = 1
index = 0
cnt = 0

while index < n:
    if a[index] == num_looking_for:
        num_looking_for += 1
    else:
        cnt += 1
    index += 1

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

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

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

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

num = 1
ans = 0
for i in range(n):
    if A[i] == num:
        num += 1
        ans += 1
if ans == 0:
    print("-1")
else:
    print(n - ans)

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

Solution (Python):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)

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

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

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

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

print(cnt if cnt <= N-1 else "-1")

Solution (Python):
from collections import deque

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

Solution (Python):
from collections import deque

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

Solution (Python):
from collections import deque

n = int(input())
a = list(map(int, input().split()))
if 1 in a:
    d = deque(a)
    count = 0
    num = 1
    pick = 0
    while d:
        pick = d.popleft()
        count += 1
        if pick == num:
            count -= 1
            num += 1

    print(count)
else:
    print(-1)

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

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

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

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

if b_num == n:
    b_num = -1

print(b_num)

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

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

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

checkNum = 1
howMany = 0

for j in range(N):
    if line[j] == checkNum:
        checkNum += 1
    else:
        howMany += 1





if checkNum == 1:
    print("-1")
else:
    print(howMany)

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

change = False
ans = 0
re = 0

for i in range(N):
    if A[i]==re+1:
        re += 1
        change = True
    else:
        ans += 1

if change == True:
    print(ans)
else:
    print(-1)

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

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

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

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

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

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

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

for i in a:
    if i == x:
        ans += 1
        x += 1

if ans == 0:
    print(-1)
else:
    print(len(a)-ans)

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

a_only = list(set(a_inputs))

ans=0
count=0
for i in range(len(a_inputs)):
    if a_inputs[i]==(count+1):
        count+=1
        continue
    else:
        ans+=1

if a_inputs==a_only:
    print(0)
elif 1 not in a_inputs:
    print(-1)
else:
    print(ans)

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

    count = 0
    search_num = 1

    for num in num_list:
        if search_num == num:
            search_num += 1
            continue
        count += 1
        
    print(count if search_num != 1 else -1)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
from collections import deque
n = int(input())
a = list(map(int, input().split()))
if a.count(1) == 0:
    print(-1)
else:
    q = deque(a)
    count = 0
    crash_count = 0
    while q:
        if q[0] != 1 + count:
            q.popleft()
            crash_count += 1
        else:
            q.popleft()
            count += 1
    print(crash_count)

Solution (Python):
_, *a = map(int, open(0).read().split())
p, c = 1, 0
for i in a:
  c += i!=p
  p += i==p
print(-1 if p==1 else c)

Solution (Python):
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    ans, cnt = N, 1
    for a in A:
        if a == cnt:
            ans -= 1
            cnt += 1
    if ans == N:
        print('-1')
    else:
        print(ans)


if __name__ == '__main__':
    main()

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

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

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

ans = 0
del_num = []

for index, i in enumerate(num):
    if i == ans + 1:
        ans += 1
    else:
        del_num.append(index)

if len(num) == len(del_num):
    print(-1)

else:
    print(len(del_num))

Solution (Python):
n = int(input())
a = map(int, input().split())
ans_lst = []
for ai in a:
    if len(ans_lst) == 0 and ai == 1:
        ans_lst.append(1)
    elif len(ans_lst) > 0 and ans_lst[-1] == ai - 1:
        ans_lst.append(ai)
if len(ans_lst) == 0:
    print(-1)
else:
    print(n - len(ans_lst))

Solution (Python):
n = int(input())
a = map(int, input().split())
ans_lst = []
for ai in a:
    if ai == 1 and len(ans_lst) == 0:
        ans_lst.append(1)
    elif len(ans_lst) > 0 and ans_lst[-1] == ai - 1:
        ans_lst.append(ai)
if len(ans_lst) == 0:
    print(-1)
else:
    print(n - len(ans_lst))

Solution (Python):
n = int(input())
a = map(int, input().split())
ans_lst = []
for ai in a:
    if ai == 1:
        ans_lst.append([1])
    else:
        for ans in ans_lst:
            if ans[-1] == ai - 1:
                ans.append(ai)
if len(ans_lst) == 0:
    print(-1)
else:
    min = 200001
    for i in range(len(ans_lst)):
        if min > len(ans_lst[i]):
            min = len(ans_lst[i])
    print(n - min)

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

cnt = 0
num = 1

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

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

num = 1
ans = 0

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

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

Solution (Python):
data=int(input())
array=list(map(int,input().split()))
counter=0
qwe=1
for i in range(data):
    if array[i]==qwe:
        counter+=1
        qwe+=1
if counter==0:
    print(-1)
else:
    print(data-counter)

Solution (Python):
import sys
from bisect import bisect_right as bsr
from collections import Counter as cnt
from collections import defaultdict as dd
from collections import deque
from fractions import gcd
from itertools import permutations as perm
from math import ceil, factorial, floor
from operator import itemgetter as ig

sys.setrecursionlimit(1000000)


args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    N = input(int)
    A = input([int, N])
    i, ans = 1, 0
    for a in A:
        if not a == i:
            ans += 1
        else:
            i += 1
    if ans == N:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

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

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

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

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

ans = n - count if count > 0 else -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(-1)
else:
    print(n-cnt)

Solution (Python):
n = int(input())
ns = map(int, input().split())
rslt = 0
num = 1
for i in ns:
    if num == i:
        num += 1
        continue
    rslt += 1
if n == rslt:
    print(-1)
else:
    print(rslt)

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

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

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

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

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

counter = 1
lista = []
for i in range(len(a)):
    if a[i] == counter:
        lista.append(a[i])
        counter += 1
if len(lista) > 0:
    print(n - len(lista))
else:
    print(-1)

Solution (Python):

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

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

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

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

nm = 1
cnt = 0

for a in A:
    if a == nm:
        nm += 1
    else:
        cnt += 1

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

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

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

print(n-ct if ct>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
        
cnt -= 1
if cnt > 0:
    print(n-cnt)
else:
    print(-1)

Solution (Python):


import bisect

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

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


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

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

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

  else:
    breaks += 1

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

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

Solution (Python):


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

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

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

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

  i = 1
  for a_i in input().split():
    if i == int(a_i):
      i += 1
  
  if i == 1:
    i = n + 2
    
  print(n - i + 1)


if __name__ == "__main__":
  main()

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

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

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

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

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

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

find = 1

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

print(-1 if find == 1 else len(A) - find + 1)

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

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

Solution (Python):
from sys import stdin
import queue
import sys
import math

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

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

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

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

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

Solution (Python):


import sys







from itertools import count, cycle, repeat     
from itertools import groupby                  
from itertools import starmap                  








def main():
    mod = 1000000007                  
    inf = float('inf')
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n = ii()
    a = lmi()
    c = 1
    ans = 0
    for i in range(n):
        if a[i] == c:
            c += 1
        else:
            ans += 1
    print(ans) if ans != n else print(-1)

if __name__ == "__main__":
    main()

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

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

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

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

Solution (Python):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

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

a = deque(a)
i = 1
ans = 0
while a != deque():
    if a[0] == i:
        a.popleft()
        i += 1
        ans += 1
    else:
        a.popleft()

print(n - ans)

Solution (Python):
def myAnswer(N:int,A:list) -> int:
   i = 1
   counter = 0
   for a in A:
      if(a == i):
         i+=1
      else:
         counter +=1
   return counter if(1 in A) else -1


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))

if __name__ == '__main__':
   main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

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

if __name__ == '__main__':
    main()

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

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

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

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

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

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

if a.count(1) == 0:
    print(-1)
    exit()

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