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

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

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

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

if suc>0:
    print(count)
else:
    print(-1)

Solution (Python):
N = int(input())
arr = list(map(int,input().split()))
num = 1
for i in range(N-1):
  if num == arr[i]:
    num += 1
    
if N>1:
  if num==1 and arr[-1]!=1:
    print(-1)
  elif num==1 and arr[-1]==1:
    print(1)
  elif num!=1 and arr[-1]==num:
    print(N-num)
  elif num!=1 and arr[-1]!=num:
    print(N-num+1)

else:
  if arr[0]==1:
    print(0)
  else:
    print(-1)

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

counter = 1
smash = 0
bl = True

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

if smash == n:
    bl = False


print(smash if bl else "-1")

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

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

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

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

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

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

n = 1
K = 0

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

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

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

index = 1
count = 0


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

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

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

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

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

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

index = 1

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

if index != 0:
    print(n - index)
else:
    print(-1)

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

Solution (Python):
from collections import deque
def check(arr):
	num=1
	Q=deque(arr)
	while len(Q):
		while len(Q) and Q[0]!=num:
			Q.popleft()
		if len(Q):
			num+=1
			Q.popleft()
	return len(arr)-(num-1)

n=int(input())
arr=[int(x) for x in input().split()]
ans=check(arr)
if ans==n:
	print(-1)
else:
	print(ans)

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

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

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

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

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

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

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

s = 0

for i in range(n):
  
  s_ = (i+1) - l[i]
  if s_ == (i-s):
    s += 1

if s != 0:
  print(n-s)
else:
  print(-1)

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

i = 1
f = False
for a in aN:
    if i == a:
        i += 1
        f = True

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

Solution (Python):
n = int(input())
a = [0] * n
a = list(map(int, input().split(' ')))

ans = 0
cnt = 1
for ai in a:
    if ai == cnt:
        cnt += 1
    else:
        ans += 1

if (cnt == 1):
    ans = -1
print(str(ans))

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

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

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

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

Solution (Python):
N = int(input())
a = [int(n) for n in input().split(' ')]
n = 1
b = []
for m in a:
    if n == m:
        b.append(m)
        n += 1

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

print(ans)

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

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

break_number = 0
pre_index = 0
cnt = 1
hantei = False
for i in range(N):
    if cnt == N and (cnt != 1):
        break
    if a[i] == cnt:
        break_number += (i-pre_index)
        pre_index = i + 1
        cnt += 1
    if i == (N-1):
        if cnt != 1:
            break_number += max(0, i-pre_index + 1)
if cnt == 1:
    print(-1)
else:
    print(break_number)

Solution (Python):
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
N=int(input())
A = list(map(int,input().split()))


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

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

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

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

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

index = 1
broke = 0

for i in A:
  if i == index:
    index += 1
  else:
    broke += 1

if index == 1:
  print(-1)
else:
  print(broke)

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

    ans = 0
    integer = 1
    for j in range(n):
        if a_list[j] == integer:
            integer += 1
        else:
            ans += 1
    if integer == 1:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

N = int(input())
A = list(map(int, input().split()))
DP = []
tmp = 0

for i in range(N):
    if A[i] == tmp +1:
        DP.append(A[i])
        tmp += 1
    else:
        pass

if len(DP) >= 1:
    print(N-len(DP))
else:
    print(-1)

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

now_i = 1
num = 0
for a_i in A_list:
    if a_i == now_i:
        now_i += 1
    else:
        num += 1
if now_i == 1:
    print(-1)
else:
    print(num)

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

count = 1
ans = 0
for x in nums:
  if x == count:
    count+=1
  else:
    ans+=1

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

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

cnt = 1
ans = 0
b = []

for i, j in enumerate(a):
    if cnt==j:
        cnt += 1
        b.append(j)
        continue
    else:
        ans += 1
        b.append(0)

if sum(b) == 0:print(-1)
else:print(ans)

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

def check(m):
    tar = 1
    for i in range(n):
        if a[i] == tar:
            tar += 1
    if tar >= m+1:
        return 1
    else:
        return 0

if check(1) == 0:
    print(-1)
else:
    l = 1
    h = n
    mid = 1
    ans = None

    while l < h:
        mid = (l+h)//2
        guess = check(mid)
        
        if guess:
            l = mid + 1
        else:
            h = mid -1

    saku = sorted([l,h,mid], reverse=True)

    if check(saku[0]):
        print(n-saku[0])
    elif check(saku[1]):
        print(n - saku[1])
    else:
        print(n-saku[2])

Solution (Python):
import sys
from pprint import pprint

def solve(n, a):
    pre = 0
    count = 0
    for a_i in a:
        if a_i == pre + 1:
            pre = a_i
            count += 1

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

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = map(int, sys.stdin.readline().strip().split(" "))
    
    solve(n, a)

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

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

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

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




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

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

Solution (Python):
import math
import fractions

N = int(input())
a = list(map(int, input().split(' ')))
current = 1
answer = 0

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
cnt = 0
i = 0
j = 0
f_flg = 0
while i < len(a) and j < len(a):
    while a[j] != i + 1:
        cnt += 1
        j += 1

        if j > len(a) - 1:
            if f_flg == 0:
                print(-1)
                exit()
            break
    f_flg = 1
    i += 1
    j += 1

print(cnt)

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


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

Solution (Python):
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    count = 0
    current = 1
    for x in a:
        if x == current:
            current += 1
        else:
            count += 1
    if count == N:
        print(-1)
    else:
        print(count)


if __name__ == "__main__":
    main()

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

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

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

Solution (Python):
import heapq

def main():
    n = int(input())
    arr = list(map(int,input().split()))
    nums = {}
    for i in range(1,n+1):
        nums[i] = []

    dp = [0]*n
    heap = []
    for i in range(n):
        nums[arr[i]].append(i)
        if arr[i] == 1:
            dp[i] = 1
            heapq.heappush(heap,(arr[i],i))

    if not heap:
        print(-1)
        return
    visited = set()
    while heap:
        curr = heapq.heappop(heap)
        if curr not in visited:
            visited.add(curr)
            index = curr[1]
            num = curr[0]
            
            if num+1 in nums.keys():
                for kid in nums[num+1]:
                    if kid > index:
                        
                        dp[kid] = max(dp[kid],dp[index]+1)
                        heapq.heappush(heap,(num+1,kid))

    
    print(n-max(dp))
    
    

main()

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

number = 1
break_countr = 0

for k in range(n):
  if(a[k] == number):
    number += 1
  else:
    break_countr += 1

if(number == 1):
  if(1 not in a):
    print(-1)
  else:
    print(break_countr)
else:
  print(break_countr)

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

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

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

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

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


if __name__ == "__main__":
    main()

Solution (Python):


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

number = 0
now_i = 1
one_flag = False
for a in A:
    if a != now_i:
        number += 1
    else:
        now_i += 1
        one_flag = True

if one_flag is False:
    print('-1')
else:
    print(number)

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

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

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

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

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

found = []
for n in range(N):
    if a[n] == len(found) + 1:
        found.append(a[n])

print(N - len(found) if len(found)!=0 else -1)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
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):
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)
    exit()

print(abs(count-1-n))

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

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

Solution (Python):
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res



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

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

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

n = int(readline())
c = 1
r = 0
p = 0
a = True
for i, j in enumerate(readline().split()):
  if c != int(j):
    continue
  else:
    a = False
    c += 1
    r += i - p
    p = i + 1
if a:
  print(-1)
else:
  print(r + n - p)

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

num = 1
ans = -1
for i in lst:
  if (num == i):
    num += 1
if (num-1 != 0):
  ans = N-num+1
print(ans)

Solution (Python):
import bisect
def main():
    N = int(input())
    a = list(map(int, input().split()))
    d = {}
    for i, v in enumerate(a):
        if v in d:
            d[v].append(i)
        else:
            d[v] = [i]
    t = -1
    r = 0
    if 1 not in d:
        return -1
    for i in range(1, N+1):
        if i not in d:
            r += N - 1 - t
            break
        j = bisect.bisect_left(d[i], t)
        if j == len(d[i]):
            r += N - 1 - t
            break
        r += d[i][j] - t - 1
        t = d[i][j]
    return r
print(main())

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

ans = 0
m = 1
flag = 0
for i in range(n):
  if nums[i] == m:
    flag = 1
    m += 1
if flag == 0:
  print(-1)
else:
  print(n-m+1)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
i=0
j=0
ans=0
if 1 in a:
    while j<N:
        if a[j]!=i+1:
            ans+=1
        else:
            i+=1
        j+=1
else:
    ans=-1
print(ans)

Solution (Python):

si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
a=nl()
cur=1
ans=0

b=set(a)

if 1 in b:
    pass
else:
    print(-1)
    exit()

flg=True
for i in range(n):
    if i==a[i]:
        pass
    else:
        flg=False

if flg:
    print(0)


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

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


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

if N-count+1 < N:
    print(N-count+1)
else:
    print(-1)

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 = [int(i) for i in input().split()]
ans = 0
cnt = 1
for i in range(N):
    if not A[i] == cnt:
        ans += 1
    else:
        cnt += 1
if ans == N:
    ans = -1
print(ans)

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

Solution (Python):
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]

fetch_one_line()
nums = fetch_int_input()
now_num = 1
remove_num = 0

for n in nums:
    if n == now_num:
        now_num += 1
    else:
        remove_num += 1


if now_num == 1:
    remove_num = -1

print(remove_num)

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

Solution (Python):
def acinput():
    return list(map(int, input().split(" ")))


N=int(input())

a=acinput()

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

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

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

tmp=0
for i in l:
    if i==tmp+1:
        tmp+=1

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

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

a_min = 1
cnt = 0
for a in a_n:
    if a == a_min:
        a_min = a + 1
    else:
        cnt += 1

if cnt == len(a_n):
    print(-1)
else:
    print(cnt)

Solution (Python):
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    A = LIST()

    check = False
    cnt = 1
    for i, a in enumerate(A):
        if a == cnt:
            check = True
            cnt += 1

    print(N - cnt + 1 if check else -1)


if __name__ == '__main__':
    main()

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

manzoku=1
hakai = 0
for i in range(N):
    if bricks[i] == manzoku:
        manzoku += 1
    else:
        hakai += 1

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

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

start = 1
broke = 0
for i in range(N):
    if array[i] != start:
        broke += 1
    else:
        start += 1

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

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

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

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
"""
data=[set() for i in range(N)]
for i in range(N):
    data[A]
"""

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

Solution (Python):
n = int(input())
array = input().split(" ")

now = 0
for i in range(0, n):
    if int(array[i]) == now+1:
        now += 1

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

Solution (Python):


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

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

if s == 0:
    print('-1')
else:
    print(n - s)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
num=1
start=0
while(start != -1):
    try:
        start=a.index(num,start)
        num+=1
    except ValueError:
        break
num-=1

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

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

if __name__ == '__main__':
    main()

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

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

count = 1
ans = 0
for num in nums:
    if num != count:
        ans += 1
    else:
        count += 1

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

Solution (Python):
input()

lst = map(int, input().split())

count = 0
current = 1
find = False
for i in lst:
  if i == current:
    current += 1
    find = True
  else:
    count += 1
if find:
  print(count)
else:
  print(-1)

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

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

Solution (Python):


N = int(input())
bricks = [a for a in map(int, input().split(' '))]
start = False
pre = 0
ans = 0

for brick in bricks:
    if not start:
        if brick == 1:
            start = True
            pre = 1
        else:
            ans += 1
    else:
        if brick == pre + 1:
            pre += 1
        else:
            ans += 1

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

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

counter = N - 1
current = 1

for a in A:
    
    if a == current:
        current += 1
    else:
        counter -= 1
    if counter < 0:
        print(-1)
        break
else:
    print(N - counter -1)

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

next_int = 1
num_break = 0

for x in A:
    if x == next_int:
        next_int += 1
        continue
    num_break += 1

result = -1 if next_int == 1 else num_break
print(result)

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

x = {}
min_value = 1
is_found = False
for i in range(n):
    if a[i] == min_value:
        min_value += 1
        is_found = True

if is_found:
    print(n - (min_value - 1))
else:
    print(-1)

Solution (Python):

n = int(input())
lis = list(map(int, input().split()))
temp = 1
for i in range(n):
    if lis[i] == temp:
        temp += 1

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

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


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

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

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


if __name__ == "__main__":
    main()

Solution (Python):

N = int(input())

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


cost = 0
cnt = 1

for a in A:
    
    if a != cnt:
        
        cost +=1
        
    
    elif a==cnt:
        cnt +=1

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

Solution (Python):
from sys import stdin 
n = int(stdin.readline().rstrip())
s = [int(x) for x in stdin.readline().rstrip().split()]
t = 1
answer = 0
for i in range(n):
    if s[i] == t:
        t += 1
    else:
        answer += 1
if answer == n:
    print(-1)
else:
    print(answer)

Solution (Python):
n = int(input())
a_list = [int(i) for i in input().split()]
key = 1
count = 0

for a in a_list:
  if a == key:
    key += 1
  else:
    count += 1

print(count if key > 1 else -1)

Solution (Python):

import sys


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

    print(-1 if nok==0 else N-nok)
    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):
N = int(input())
bricks = map(int, input().split())

ans = 0
num = 1

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

if ans == N:
    ans = -1

print(ans)

Solution (Python):
import numpy as np

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

ans = 0
now_number = 1

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

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

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

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

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

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

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

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

l = 0

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


if l == 0:
    print('-1')
else:
    print(N - l)

Solution (Python):
import sys 

readline = sys.stdin.buffer.readline

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

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

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


main()

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

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

if cnt == 0:
    print(-1)
    exit()
ans = n-cnt
print(ans)

Solution (Python):

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

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


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

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

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

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

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
a = [0]+list(map(int, input().split( )))
tmp = 0
cnt =0
if 1 not in a:
    print(-1)
    exit()
for i in range(n+1):
    while tmp <= n and a[tmp]!=i:
        tmp += 1
        cnt += 1
        
    tmp += 1
    if tmp > n:
        break


print(cnt)

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

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

l=1
k=0
while k<=n-1:
    for i in range(k,n):
        if a[i]==l:
            l+=1
            k=i+1
            break
    else:
        k=n
if l==1:
    print(-1)
else:
    print(n-l+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(n-(now-1))
else:
	print(-1)

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

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

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

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

Solution (Python):
from sys import stdin

if __name__ == '__main__':
    N = int(stdin.readline().strip())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    
    current_num = 1
    broken_num = 0
    for i in range(N):
        if a[i] != current_num:
            broken_num += 1
        else:
            current_num += 1
    if current_num > 1:
        print(broken_num)
    else:
        print(-1)

Solution (Python):
def d(caps):
    start = count = 0
    num = 1
    for i in range(len(caps)):
        if caps[i] != num:
            count += 1
        else:
            num += 1
    
    if num == 1:
        print(-1)
    else:
        print(count)

input()
s = [int(i) for i in input().rstrip().split(' ')]

d(s)