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()))


cur = 1
ans = 0

for i in a:
    if i != cur:
        ans += 1
    elif i == cur:
        cur += 1

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

Solution (Python):
n = int(input())
l = list(map(int, input().split()))
if not 1 in l:
  print(-1)
  exit()
cnt = 1
ans = 0
for item in l:
  if item == cnt:
    ans += 1
    cnt += 1
print(n - ans)

Solution (Python):
import bisect

INF = 1 << 30

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

ans = 0
now = 1

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

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

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

if a==(list(i+1 for i in range(N))):
       print(0)
       exit()

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

Solution (Python):
count,ans,point = 1,0,0
n = int(input())
t = list(map(int,input().split()))
for i,j in enumerate(t):
	if j == count:
		ans += i - point
		point = i + 1
		count += 1
if not point == n:
	ans += n - point
if count == 1:
	try:
		t.index(1)
	except:
		ans = -1
print(ans)

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

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

c=0
z=1
f=0

for i in range(0,N):
  if a[i]!=z:
    c+=1
  else:
    f=1
    z+=1
if f==0:
  print("-1")
else:
  print(c)

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

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

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

cnt = 0
cur = 1
for x in A:
    if x == cur:
        cur += 1
    else:
        cnt += 1

print(cnt if cnt != len(A) else -1)

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

for i in range(0,l):
  if a[i] != m:
    n+=1
  elif a[i] == m:
    m+=1

if l == n:
  print("-1")
else:
  print(n)

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

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

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

Solution (Python):
N = int(input())
nums = [int(e) for e in input().split()]

judge = False
count = 0
for i in range(N):
    if nums[i] == count+1:
        count += 1

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

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

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

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

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

Solution (Python):


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

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

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

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

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

num,pt,n_pt,count = 1,-1,0,0
while n_pt < len(A):
    if A[n_pt] == num:
        count += n_pt - pt -1
        pt = n_pt
        num += 1
    n_pt += 1
if pt != -1:
    count += len(A) - pt -1
    print(count)
else:
    print(-1)

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

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

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

ret = 0
cursor = 1

for a in A:
  if a != cursor:
    ret += 1
  else:
    cursor += 1
    
if ret < N:
  print(ret)
else:
  print(-1)

Solution (Python):
n = int(raw_input())
a = map(int,raw_input().split())
c = 0
for i in xrange(n):
  if a[i] == c+1:
    c += 1
res = n-c
if res == n:
  print -1
else:
  print res

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
count = 0
position = 0
while position < N:
  for j in range(1,N+1):
    for i in range(position,N):
      if A[i] == j:
        count = count + 1
        position += 1
        break
      else:
        position = position + 1

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

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

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

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

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

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

counts = 1
counters = 0
for x in a:
    if(x == counts):
        counts += 1
    else:
        counters += 1

if(counts == 1):
    print(-1)
    exit()
print(counters)

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

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

max_no = 0
cnt_break = 0

for i in list_num:
  if i == max_no + 1:
    max_no = i
    continue
  cnt_break = cnt_break + 1


if max_no == 0:
  print(-1)
else:
  print(cnt_break)

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

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

Solution (Python):
import math


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


def inputInt():
    return int(input())


def main():
    N = inputInt()
    a = inputIntList()
    ans = 0
    look = 1
    for i in a:
        if look == i:
            look += 1
        else:
            ans += 1

    return ans if ans != N else -1


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

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

ans = 0
i = 1
while len(a):
    ai = a.pop()
    if ai == i:
        i += 1
    else:
        ans += 1
if i == 1:
    ans = -1
print(ans)

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

if len(a) == 1 and a[0] == 1:
    ans = 0
else:
    ans = 0
    i = 1
    while len(a):
        ai = a.pop()
        if ai == i:
            i += 1
        else:
            ans += 1
    if i == 1:
        ans = -1
print(ans)

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

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

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
now = 1 
for i in range(N):
	if now == A[i]:
		now += 1 
if now == 1 :
  	print(-1)
else:
	print("{}".format(N - now + 1))

Solution (Python):



import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

from fractions import gcd

n = int(input())
a = [int(i) for i in readline().split()]


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

if now != 1:
    print(ans)
else:
    print(-1)

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

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

cnt = 0
track = 1

for i in range(n) :
	if cnt!=1 :
		if arr[i]!=track :
			arr[i] = -1
		else :
			track+=1
			cnt = 1
	else :
		if arr[i] == track :
			track+=1
		elif arr[i] == track - 1 :
			continue
		else:
			arr[i] = -1



res = set(arr)



if -1 in res :
	res.remove(-1)

ans = n - len(res)

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

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

if min(a) >= 2:
        print(-1)
        exit()

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

M = 2

for i in range(k+1, N):
    if a[i] != M:
        count += 1
    else:
        M+= 1
        

print(count)

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

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

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

Solution (Python):
n = int(input())
li = list(reversed(list(map(int, input().split()))))
li_a = []
a = 1
c = 0
while c<n:
  c += 1
  b = li.pop()
  if b == a:
    a += 1
if a == 1:
  print(-1)
else:
  print(n-a+1)

Solution (Python):
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
a = MAP()

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


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

Solution (Python):

import sys
input = sys.stdin.readline


n = int(input().strip())
A = map(int, input().strip().split())

s = 1
c = 0

for a in A:
    if a == s:
        s += 1
    else:
        c += 1

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

Solution (Python):



def correct():
    N = int(input())
    list_a = [int(a) for a in input().split()]

    nxt = 1
    ans = 0
    for a in list_a:
        if a == nxt:
            nxt += 1
        else:
            ans += 1
    if ans == N:
        ans = -1

    print(ans)


if __name__ == "__main__":
    correct()

Solution (Python):
def hantei(n,data):
    v = 1

    for st in data:
        if st == v:
            v = v + 1

    if v == 1:
        return -1
    else:
        return n - v + 1

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

print(hantei(n,data))

Solution (Python):
def mainFunc():
    N = int(input())
    arr = list(map(int, input().split(" ")))
    K = 1

    for i in range(len(arr)):
        if K == arr[i]:
            K += 1
    
    if K == 1:
        print(-1)
    else:
        print(N - K + 1)

mainFunc()

Solution (Python):
import sys

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

n = ni()
a = na()

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


print(n-x+1 if x > 1 else -1)

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v

def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None


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

    if min(A) != 1:
        print(-1)
        return

    c = 1
    ans = 0

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

main()

Solution (Python):
n = int(input())
k = 0
for x in map(int, input().split()):
    if x == k + 1:
        k += 1
print(n-k if k 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(-1)
else:
	print(n-cnt+1)

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

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

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

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

c = 0
for x in X:
    if x == c+1:
        c+=1
if c == 0:
    ans = -1
else:
    ans = N-c
print(ans)

Solution (Python):
n = int(raw_input())
bricks = raw_input().split()
bricks = [int(i) for i in bricks]
smash = 0
result = []
pos = 1
if 1 not in bricks:
  smash = -1
else:
  for i in bricks:
    if i == pos:
      pos = pos+1
    else:
      smash = smash + 1
print smash

Solution (Python):
_,a=open(0)
i=1
c=0
for a in a.split():f=int(a)!=i;c+=f;i+=f^1
print(-(i<2)or c)

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

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

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

print(-1 if v==1 else N-v+1)

Solution (Python):
n = int(input())
l = [int(i) for i in input().split()]
 
ct = 1
ans = 0
for i in range(n):
  if l[i] == ct:
    ans += 1
    ct += 1
  else:
    pass
        
print(n - ans if ans > 0 else -1)

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

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

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

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

print(ans if ans < N 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(-1)
    exit()
print(n-cnt+1)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
i = k = 0
try:
  while True:
    i = a.index(k + 1, i) + 1
    k += 1
except ValueError:
  print(n-(k or n+1))

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

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

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

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)
    exit()
print(n - cnt)

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(-1)
    exit()
print(n-cnt+1)

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

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

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

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

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

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

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

Solution (Python):
import numpy as np
i8 = np.int64


def solve(a):
    x = 1
    res = 0
    for i in range(a.shape[0]):
        if a[i] == x:
            x += 1
        else:
            res += 1
    return res


def main():
    stdin = open('/dev/stdin', 'rb')
    pin = np.fromstring(stdin.read(), i8, sep=' ')
    n = pin[0]
    a = pin[1:]
    ans = solve(a)
    if ans == n:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
import sys

read = sys.stdin.read
N, *a = map(int, read().split())

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

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

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

x = 1

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

print(n - x + 1 if x > 1 else -1)

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

S=0
ans =-1
x=1

if 1 in A:
    ans = 0
    for i in A:
        if i ==x :
            x += 1
    ans = N - x +1
            
print(ans)

Solution (Python):

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

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

Solution (Python):


def resolve():
    N=int(input())
    c=1
    cc=0
    A=[int(i) for i in input().split()]
    for i in A:
        if c==i:
            c+=1
        else:
            cc+=1
    print(cc if cc!=N else -1)



if __name__ == "__main__":
    resolve()

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

target_number=1

for i in range(N):
  if(numbers[i]==target_number):
    target_number+=1
  
if(target_number>1):
  print(N-target_number+1)
  
elif(target_number==1):
  if(1 in numbers):
    print(N-1)
  else:
    print(-1)

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

tar = 1
for a_ in A:
    if a_ == tar:
        tar += 1
tar -= 1

if tar:
    print(N - tar)
else:
    print(-1)

Solution (Python):
import numpy as np

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

nxt = 1
ans = 0

for data in x:
	if nxt == data:
		nxt += 1
	else:
		ans += 1
if ans == N:
	ans = -1

print(ans)

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
 
n = int(readline())
num = 1
res = 0
for i in readline().split():
  if num != int(i):
    res += 1
  else:
    num += 1
if res == n:
  print(-1)
else:
  print(res)

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

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

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

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

Solution (Python):
N = int(input())
ori = [int(i) for i in input().split()]
count = ori.count(1)
if count == 0:
    print(-1)

else:
    savepoint = 0
    for j in range(1,N+1):
        for i in range(savepoint,N):
            if ori[i] == j:
                savepoint = i
                
                
                sub = j
                break
        if i == N-1:
            break
    print(N-sub)

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

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

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

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

Solution (Python):


n = int(input())
a_list = list(map(int,input().split()))
count = 0
i = 1

if not 1 in a_list:
    print("-1")
    exit()

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

print(len(a_list)-count)

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

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

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

    else:
        smash += 1

print(smash)

Solution (Python):

import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, a: "List[int]"):
    t = 1
    c = 0
    for i in range(N):
        if a[i] != t:
            c += 1
        else:
            t += 1

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

    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):
count = 1
destroy = 0
N = int(input())
List=list(map(int,input().split()))
isSuccess = False

if len(List) == 1:
  if List[0] == 1:
    print(0)
  else:
    print(-1)
else:
  for i in range(N):
    if List[i] != count:
      destroy += 1
    else:
      count += 1
      isSuccess = True
  if isSuccess == False:
    print(-1)
  else:
    print(destroy)

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

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

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

res=n
for i in range(1,n+1):
    res-=l[i]

if res==n:
    res=-1
    
print(res)

Solution (Python):
from sys import stdin


n = int(stdin.readline().rstrip())
arr = [int(x) for x in stdin.readline().rstrip().split()]

rslt = []

ex = 0
cntr = 1
bb = 0

for a,j in enumerate(arr):
    if j == cntr:
        cntr += 1
    else:
        bb += 1


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

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

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


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

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

print(N-ans+1)

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

X = 1
broken = 0

if  1 not in brick_nums:
    print(-1)

else:
    for i in range(N):
        if X == brick_nums[i]:
            X += 1
        else:
            broken += 1
        
    print(broken)

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

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

ans=0
now=1

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

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

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

    try:
        most_left_one = A.index(1)
    except ValueError:
        return -1  

    ans = most_left_one  
    current_searching = 1
    for a in A[most_left_one:]:
        if current_searching == a:
            current_searching += 1
        else:
            ans += 1
    return ans

print(d_brick_break())

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

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

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

print(ans if ans < N else -1)

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


def main():
  
  if 1 not in a:
    print(-1);exit()

  b=deque(a)
  

  i=1
  cnt=0
  while True:

    if len(b)==0:
      break

    if b[0]!=i:
      cnt+=1
      b.popleft()

    else:
      cnt+=0
      b.popleft()
      i+=1

    

  print(cnt)

  
main()

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

ct = 1
ans = 0
if n == 1:
    print(0 if l[0] == 1 else -1)
else:
    for i in range(n):
        if l[i] == ct:
            ans += 1
            ct += 1
        else:
            pass
        
    print(n - ans if ans > 0 else -1)

Solution (Python):
N=int(input())
A=[int(x) for x in input().split()]
ne=1
c=0

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


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

Solution (Python):
N = int(input())
li = [int(i) for i in input().split()]
ans = -1
el = 1
sum = 0
for i in range(N) :
    if li[i] == el :
        el+=1
        sum+=1
de = N - sum
if de != N :
    ans = de
print(ans)

Solution (Python):
_,a=open(0)
i=1
c=0
for a in a.split():f=int(a)!=i;c+=f;i+=f^1
print(-(i<2)or c)

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

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

ans, nxt = 0, 1

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

if ans == N:
  ans = -1

print(ans)

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

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

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

for i in range(N):
    if Ans+1 == s1[i]:
        Ans += 1

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

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

t = 1
ans=0

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

for i in range(N):
    if list[i]==t:
        t+=1
    else:
        ans+=1

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

else:
    print(ans)

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

for i in range(1, n):
  for a in A:
    if i == a:
      i += 1
      break
    else:
      ans += 1

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

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

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

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

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

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

Solution (Python):
import sys

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

try:
  bricks.index(1)
except:
  print(-1)
  sys.exit()

result = 0
numbers = []
watch = 1
for i in range(n):
  if bricks[i] == watch:
    watch = watch + 1
  else:
    result = result + 1

print(result)

Solution (Python):
n = int(input())
k = 0
for x in map(int, input().split()):
  if x == k + 1:
    k += 1
print(n-(k or n+1))

Solution (Python):
num, bricks, count, smash = int(input()), [int(x) for x in input().split(" ")], 1, 0
for x in bricks:
    if count == x: count += 1
    else: smash += 1
print(smash if smash != len(bricks) else 0 if len(bricks) == 1 else -1)

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


if __name__ == "__main__":
    main()

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



def main():
    N = int(input())
    a_l = [int(i) for i in input().split()]
    if 1 not in a_l:
        print(-1)
        sys.exit()
    counter = 1
    b = 0
    for i in a_l:
        if i == counter:
            counter += 1
        else:
            b += 1
    print(b)
    sys.exit()


if __name__ == "__main__":
    main()

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

t = 1
b = 0

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

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

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

Solution (Python):


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

t = 1
ans = 0

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

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