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

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int, input().split()))
    if not 1 in a:
        print(-1)
        exit()
    f = a.index(1)
    c = 2
    ans = f-1
    for i in range(f,N):
        if a[i] == c:
            c += 1
        else:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a_list = list(map(int,input().split()))
n_len = len(a_list)
left = 0
count = 0
for i in range(1,n+1):
    for j in range(left,n):
        if a_list[j] == i:
            count += 1
            break
    left = j + 1
if count == 0:
    print(-1)
else:
    print(n_len-count)

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

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

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

if renga>1:
  print(ans)
else:
  print(-1)

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

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    n = int(readline())
    a = [int(i) for i in readline().split()]
    j = 1
    for i in a:
        if i == j:
            j += 1
    if j-1 == 0:
        print(-1)
        return
    print(n-(j-1))
if __name__ == '__main__':
    main()

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

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

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


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

flag = False
for a in A:
    if a ==1:
        flag = True
    
if flag:
    print(cnt_no)
else:
    print('-1')

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

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

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

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

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

Solution (Python):
import bisect
n=int(input())
a=list(map(int,input().split()))
c=max(a)
ct=[[0] for _ in range(c+1)]
for i in range(n):
	ct[a[i]].append(i+1)
ans = -1
memo = -1
for j in range(c+1):
	if max(ct[j])>memo:
		ans += 1
		memo = ct[j][bisect.bisect_right(ct[j], memo)]
	else:
		break
if ct[1]==[0]:
	print(-1)
else:
	print(n-ans)

Solution (Python):
n=int(input())
a=[0]*n
def int1(x):
  return int(x)-1
a[:]=map(int1,input().split())

r=0


ii=0
for jj in range(n):
  if a[jj]==ii:
    r+=1
    ii+=1
if r==0:
  print(-1)
  exit()

print(n-r)

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

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

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

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

B=[i for i in range(1,N+1)]
C=[]
ans=0
for i in B:
    while A:
        x=A.popleft()
        if i!=x:
            ans+=1
        else:
            C.append(x)
            break
if C==[]:
    print(-1)
else:
    print(ans)

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

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

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

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

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









ans = []
i = 1
for j in range(n):
  if i == a[j]:
    i += 1
    ans.append(i)

print(n - len(ans) if 1 in a else -1)

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

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

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

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

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

Solution (Python):
import numpy as np

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

search = 1

if a.min()>1:
    print(-1)
else:
    for i in range(N):
        if a[i]==search:
            search += 1
        else:
            continue
    else:
        print(N-search+1)

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

Solution (Python):
import copy
from collections import deque
import bisect

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

i = 1
sum = 0
end = False
while True:
    while A[0] != i:
        A.popleft()
        sum += 1
        if len(A) == 0:
            end = True
            break

    if end == True:
        if i == 1:
            sum = -1
        break

    A.popleft()
    i += 1
    if len(A) == 0:
        break

print(sum)

Solution (Python):

N= int(input())
A = [int(j) for j in input().split()]
ans = 0
for i in range(N):
    if A[i] != i - ans+1:
        ans+=1
if ans == N:
    print(-1)
else:
    print(ans)

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

current_idx = -1
next_num = 1
broken = 0
success = False

while broken < n:
    
    found = False
    for idx in range(current_idx + 1, n):
        if as_[idx] == next_num:
            
            current_idx = idx
            next_num += 1
            found = True
        else:
            broken += 1

    if n - broken == next_num - 1:
        success = True
        break

if n - broken > 0 and success:
    print(broken)
else:
    print(-1)

Solution (Python):
from sys import stdin, setrecursionlimit


def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    num = 1
    for ai in a:
        if ai == num:
            num += 1
        else:
            ans += 1
    if num == 1:
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
N = int(input())
lis = list(map(int,input().split()))
count = 0
search = 1
result = -1
rest = 0
for i in lis:
    if i == search:
        search += 1
        rest +=1
    else:
        count +=1

if rest == search-1 and rest != 0:
    result = count

print(result)

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

Solution (Python):
N = int(input())
A = tuple(map(lambda n: int(n) - 1, input().split()))

rem = 0
bk = 0
for a in A:
    if a == rem:
        rem += 1
    else:
        bk += 1

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

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

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

    import itertools

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































if __name__ == "__main__":
    main()

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

ans = 0
idx = 1

for i in a:
    if i != idx:
        ans += 1
    else:
        idx += 1

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

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

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

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

Solution (Python):


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

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

c=1
ans = 0
while(len(a)>0):
  if c== a.pop():
    c+=1
  else:
    ans+=1

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

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

num = 1
i = 0
while i <= N-1:
    if la[i] == num:
        num += 1
    i += 1

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

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

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

ans = N - found if found > 0 else -1
print(ans)

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

break_cnt = 0
next_num = 1
for a in a_list:
    if a == next_num:
        next_num +=1
    else:
        break_cnt+=1

if break_cnt != n:
    print(break_cnt)
else:
    print(-1)

Solution (Python):
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))

def main(n,a):
    if (not 1 in a):return -1
    res = 0
    idx = 1
    for i in a:
        if i != idx:
            res += 1
        else:
            idx += 1
    return res
    
n = ii()
a = mi()
print(main(n,a))

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

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

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

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

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools
import heapq


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(input):
    bricks = string_to_int(input)
    count = 1
    broken = 0
    for b in bricks:
        if b == count:
            count += 1
            continue
        broken += 1

    return -1 if broken == len(bricks) else broken


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(input())
    print(ret)

Solution (Python):
n = int(input())
t = [False]*(n+1)
t[0] = True
l = [int(i) for i in input().split()]
ans = 0
for i in range(n):
  x = l[i]
  if t[x-1]:
    t[x] = True
    ans = max(ans, x)
print(n-ans if ans > 0 else -1)

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

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

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

print(ans)

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

Solution (Python):

"""
Created on Sat May  9 16:33:03 2020

@author: shinba
"""


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

if 1 in a:
    print(cnt)
else:
    print(-1)

Solution (Python):
N = int(input())
ls = list(map(int, input().split()))
counter = 1
for elem in ls:
    if elem == counter:
        counter += 1
if counter == 1:
    print(-1)
else:
    print(N - counter + 1)

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):
def main():
    N=int(input())
    a=[int(_) for _ in input().split()]
    ans=0
    for i,v in enumerate(a):
        if v==ans+1:
            ans += 1
    print(-1 if ans==0 else N-ans)

main()

Solution (Python):
def StalinSort(L):
    """スターリンソート
    参考
    https://qiita.com/Sirloin/items/c9e5c74be3366df65bce
    ソート対象のリストを先頭要素から調べて、昇順になっていない要素をリストで返す
    input   L:ソート対象のリスト
    output  purge:昇順になっていない（邪魔になる）要素のリスト
    """

    targ = 1
    purge = []
    for l in L:
        if l != targ:
            purge.append(l)
        else:
            targ += 1
    return purge

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

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

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

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

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

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

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

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

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

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

for i in range(N):
  if i != N-1 and a[i] == j:
    j += 1
  
  elif i != N-1 and a[i] != j:
    ans += 1

  elif i == N-1 and a[i] == j:
    break
  
  else:
    ans += 1
    break

if N == 1 and a[0] == 1:
  ans = 0
    
elif ans == N:
  ans = -1
  
print(ans)

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

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

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

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

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

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

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

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

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

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

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

if k == 1:
    print(-1)
else:
    print(len(an) - k + 1)

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

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

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

if __name__ == '__main__':
    main()

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

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

Solution (Python):
def main():
    N = int(input())
    a = input().split()
    for i in range(N):
        a[i] = int(a[i])
    j = 1
    for i in range(N):
        if(j == a[i]):
            j += 1
    if j > 1:
        print(N-j+1)
    else:
        print(-1)
        
if __name__ == '__main__':
    main()

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

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

print(count if i > 1 else -1)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

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

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

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

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))

from fractions import gcd
def resolve():
    N,=pin()
    A=tupin()
    
    if 1 not in A:print(-1);return
    suuji=0
    ans=0
    for a in A:
        if a==suuji+1:
            suuji+=1
        else:ans+=1
    print(ans)

resolve()

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

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

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

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce


import sys
def I(): return int(input())  
def Is(): return map(int, input().split())  
def LI(): return list(map(int, input().split()))  
def TI(): return tuple(map(int, input().split()))  
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  
def LS(): return list(input())  
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

n = I()
A = LI()

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

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

Solution (Python):


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

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

print(len(A) - len(ls) if 0 < len(ls) else -1)

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

cnt =0
index =1
i=0
while i <N:
    if lenga[i]!=index:
        cnt+=1
    else:
        index+=1

    i+=1

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

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

num = [0 for i in range(n + 1)]
tugi = 1
count = 0
flag = False

for i in range(n):
    if a[i] == 1:flag = True
    if a[i] != tugi:
        count += 1
    else:
        tugi += 1

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

Solution (Python):


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

count = 1
ans_list = []
for i in range(n):
    if a[i] == count:
        count += 1
        ans_list.append(count)

if len(ans_list) == 0:
    print(-1)
else:
    print(n-len(ans_list))

Solution (Python):
import numpy as np
import math
import scipy
import itertools

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

if __name__ == "__main__":
    solve()

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

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

c = 1
ans = 0

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

Solution (Python):
def main():
    ind = int(input())
    t = list(map(int, input().split()))
    ans = []
    for i in range(ind):
        if len(ans) + 1 == t[i]:
            ans.append(t[i])
    count = -1 if len(ans) == 0 else ind - len(ans)
    print(count)



if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
def main():
    N = int(input())
    a_list = list(map(int, input().split(' ')))
    broken_cnt = 0
    remain_max_number = 0
    for a in a_list:
        if a == remain_max_number + 1:
            remain_max_number += 1
        else:
            broken_cnt += 1
    answer = broken_cnt if broken_cnt < N else -1
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):


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

    n = 1
    s = 0

    for _ in a:
        if _ == n:
            n += 1
        else:
            s += 1
    if n == 1:
        print(-1)
    else:
        print(s)


main()

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

res = 0
i = 1
for a in A:
    if a != i:
        res += 1
        continue
    i += 1

if res == N:
    res = -1

print(res)

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

next_number = 1
num_broken = 0

for brick in bricks:
  if brick == next_number:
    next_number += 1
  else:
    num_broken += 1
    
if next_number == 1:
  print(-1)
else:
  print(num_broken)

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

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

val = 1
ans = 0
for a_i in a:
    if a_i == val:
        val += 1
    else:
        ans += 1

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

Solution (Python):

import sys


def solve(N: int, a: "List[int]"):
    num = 1
    count = 0

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

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

"""
Created on Sun May  3 19:04:26 2020

@author: Kanaru Sato
"""

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")
else:
    print(n-target+1)

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

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

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

cnt = 1
ans = 0

for a in ali:
    if a == cnt:
        cnt = cnt + 1
    else:
        ans = ans + 1

if ans == N:
    ans = -1

print(ans)

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

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

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

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

index = 1
cnt = 0
for i in range(len(a)):
  if a[i] != index:
    cnt +=1
  else:
    index +=1
    
if min(a)!=1:
  print("-1")
else:
  print(cnt)

Solution (Python):
n,*a=map(int,open(0).read().split())
cnt=1
for i in range(n):
  if a[i]==cnt:
    cnt+=1
if n>1:
  if cnt>1:
    print(n-cnt+1)
  else:
    print(-1)
else:
  if a[0]==1:
    print(0)
  else:
    print(-1)

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

for n in range(N):
  if a[n]==num:
    num +=1

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

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

ans = 0
n = 1

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

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

Solution (Python):

import sys
N = int(input())
A=[int(i) for i in input().split()]



if 1 not in A:
    print(-1)
    exit
else:
    i=1 
    brick_remain =set() 
    for a in A:
        if a ==i:
            brick_remain.add(a)
            i +=1
    brick_destroy = N - len(brick_remain)       
    print(brick_destroy)

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

if __name__=='__main__':
  main()

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

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

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

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

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

count = 0
i = 0
val = 1
while i < n:
    while(i < n and a[i] != val):
        i = i + 1
        count = count + 1
    
    if(i < n):
        i = i + 1
        val = val + 1

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

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

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