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.



Sample input:
3
2 1 2


Sample output:
1

Submission status: Accepted

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

    #inf = 10**17
    #mod = 10**9 + 7

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = 1
    for i in range(n):
        if a[i] == k:
            k += 1
    k -= 1
    print(n - k) if k else print(-1)

main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    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 num == 1:
        print(-1)
    else:
        print(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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(N-cnt)
else:
    print(-1)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    arr = list(map(int, input().split()))
    exp = 1
    for num in arr:
        if exp == num:
            exp += 1

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

resolve()

Submission status: Accepted

Solution code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
cur = 0
for a in A:
    if a == cur + 1:
        cur += 1

print(N-cur if cur > 0 else -1)
# 54

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
#n,m=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(m)]

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

Submission status: Accepted

Solution code:
import bisect
N = int(input())
arr = list(map(int,input().split()))
cnt = [[] for i in range(N + 1)]

for i in range(N):
    num = arr[i]
    cnt[num].append(i)

sunuke = []

for i in range(1,N + 1):
    if cnt[i] == []:
        break
    if i == 1:
        sunuke.append(cnt[1][0])
        continue
    else:
        j = bisect.bisect_left(cnt[i],sunuke[-1])
        if j == len(cnt[i]):
            break
        else:
            sunuke.append(cnt[i][j])
print(N - len(sunuke) if len(sunuke) > 0 else -1)

Submission status: Accepted

Solution code:
#python3
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    k = 1
    for i in range(n):
        if a[i] == k:
            k += 1
    k -= 1
    print(n - k) if k else print(-1)  

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
x=int(input())
a=list(map(int, input().split()))

ans=0
p=0

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

if p==0:
	print(-1)
else:
	print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
i = 0
check = 1
satisfy = [False for i in range(n)]
break_block = 0
while i < n:
    if a[i] == check and not satisfy[check - 1]:
        satisfy[check - 1] = True
        check += 1
    else:
        break_block += 1
    i += 1
if not satisfy[0]:
    print(-1)
else:
    print(break_block)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = []
a = list(map(int,input().split()))
index = 0
count = 0
searchNum = 1
if not 1 in a:
    count = -1
else:
    for j in range(N):

        if a[j] ==searchNum:
            searchNum += 1
            continue
        else:
            count +=1
print(count)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
K = 0
ans = 0

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

if K == 0:
    ans = -1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
current = 0
for a in a_list:
    if a == current + 1:
        current += 1
if current > 0:
    print(N-current)
else:
    print(-1)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N=int(input())
a=input().split()
A=[int(b) for b in a]
n=1
for a in A:
    if a==n:
        n+=1
if n==1:
    print(-1)
else:
    print(N-n+1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt = 0
target = 1
if 1 not in a:
    print(-1)
else:
    for i in range(len(a)):
        if a[i] == target:
            a[i] = '_'
            target += 1
        
    result = [x for x in a if x != '_']

    print(len(result))

Submission status: Accepted

Solution code:
n = int(input())
alist = list(map(int,input().split()))
count = 1
broken = 0
flag = False
for i in range(0,n):
    if alist[i] == count:
        count += 1
    else:
        broken += 1

if 1 in alist:
    print(broken)
else:
    print('-1')

Submission status: Accepted

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

ans = 0
num = 1
flag = False

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

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

Submission status: Accepted

Solution code:
n = int(input())

tmp = [int(s) for s in input().split()]

target = 1
flag = 0
for i in range(n):
    if(tmp[i] == target):
        flag = 1
        target += 1
#print(target)
if(flag == 0):
    print(-1)
else:
    print(n - target +1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

N=int(input())

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

ans=0
now=1
old=0

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))

# print(L)

flg = 0

for i in L:
    if i == (flg + 1):
        flg += 1

if flg > 0:
    print(len(L) - flg)
else:
    print(-1)

Submission status: Accepted

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



if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
N = int(input())
brick = list(map(int, input().split()))
n = 0
br = 0
flg = False
for b in brick:
    if b == n + 1:
        n += 1
        flg = True
    else:
        br += 1
if flg:
    print(br)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
aa = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:

def submit():
    n = int(input())
    alist = list(map(int, input().split()))

    curr = 0
    for a in alist:
        if a == curr + 1:
            curr += 1
    
    if curr == 0:
        print(-1)
    else:
        print(n - curr)


if __name__ == "__main__":
    submit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

count = 0

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

Submission status: Accepted

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

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

i = 1
cnt = 0
for ai in a:
    if ai != i:
        cnt += 1
    elif ai == i:
        i += 1

print(cnt)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    if 1 not in a:
        print(-1)
        return
    ans = 0
    nxt = 1
    for i in range(N):
        if a[i] == nxt:
            nxt += 1
        else:
            ans += 1
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
num = list(map(int, input().split()))
cnt = [1]*n
flug = 1
for i in range(n):
  if num[i] == flug:
      cnt[i] = 0
      flug += 1
if sum(cnt) == n:
  print(-1)
else:
  print(sum(cnt))

Submission status: Accepted

Solution code:
n=int(input())
a=map(int,input().split())
i=1
for k in a:
  if k==i: i+=1
print(n-i+1 if i>1 else -1)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
li = [int(x) for x in input().split()]
ans = 0
x = 1
for i in range(n):
    if li[i]==x:
        x+=1
    else:
        ans+=1

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

S = list(map(int,input().split()))
if 1 not in S:
  print(-1)
else:
  start = 1
  for i in S:
    if i == start:
      start+=1
  else:
    print(N-start+1)

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline().strip())
nums = map(int, sys.stdin.readline().split())
nums = list(nums)
if 1 not in nums:
    print(-1)
    sys.exit(0)
crt = 1

for i in range(n):
    if nums[i] == crt:
        crt += 1
    
print(n - crt + 1)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


n = int(input())
a_list = list(map(int,input().split()))
ans = len(a_list)
ini = 1
for l in a_list:
    if l == ini:
        ans -= 1
        ini += 1

if ans < len(a_list):
    print(ans)
else:
    print(-1)

Submission status: Accepted

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

count = 0
for a_i in a:
    if a_i == count+1:
        count += 1
        check = 1

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9 +7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()
l = inputIL()

now = 0
boom = 0
for i in l:
  if i != now + 1:
    boom += 1
  else:
    now += 1
    
if boom == N:
  print("-1")
else:
  print(boom)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
N = int(input())
a = list(map(int,input().split()))
c = 1
n = 0
for i in range(N):
    if a[i] == c:
        c += 1
    else:
        n += 1
if c == 1:
    print(-1)
else:
    print(n)

Submission status: Accepted

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

rem = []
count = 1
for i in range(len(arr)):
    if count == arr[i]:
        rem.append(arr[i])
        count += 1

if len(rem) == 0:
    print(-1)
else:
    print(len(arr) - len(rem))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    a = list(map(int,input().split()))
    now,count = 1,0
    for num in a:
        if num == now:
            count += 1
            now += 1
    
    print(N-count if count!=0 else -1)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools
import sys
import math
import numpy as np
import fractions
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
from bisect import insort
sys.setrecursionlimit(10**9)

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

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

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

    print(N - ch_max)




if __name__ == "__main__":
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import fractions 
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  count = 1
  ans = 0
  for i in range(n):
    if a[i] != count:
      ans += 1

    else:
      count += 1
  if count == 1:
    print(-1)
  else:
    print(ans)
  
  
solve()

Submission status: Accepted

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

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

if not nums:
    print('-1')
else:
    print(len(a) - len(nums))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())
num_list = [int(a) for a in input().split()]
target = 1
ans = 0
flg = False

for i in range(num):
    if num_list[i] == target:
        target += 1
        flg = True
    else:
        ans += 1

if not flg:
    ans = -1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import bisect
# import heapq
# from copy import deepcopy
# from collections import deque
# from collections import Counter
# from itertools import accumulate
# from itertools import permutations
# import numpy as np
# import math
# mod = 10**9 + 7

n = int(input())

# s = deque(input())
# q = int(input())

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

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

print(n-c if c > 0 else -1)

Submission status: Accepted

Solution code:
#148_D
n = int(input())
a = list(map(int, input().split()))

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

Submission status: Accepted

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


l = []
ans = 0

cnt = 1

flg = True

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


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007
"""
#N,K,Mが入力
    n,k,m=LI() 
    #N
    #x1 y1
    #.  .
    #xn ynが入力
    N=I()
    p=LIR(N)
    print(n,k,m,p)
"""
def resolve():
    n=I()
    a=LI()

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

    return

import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3
2 1 2"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3
2 2 2"""
        output = """-1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """10
3 1 4 1 5 9 2 6 5 3"""
        output = """7"""
        self.assertIO(input, output)
    def test_入力例_4(self):
        input = """1
1"""
        output = """0"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

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

cnt = 1
delete = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
count = 1

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

c = 0
for i, x in enumerate(a):
    if x == c + 1:
        c += 1

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

Submission status: Accepted

Solution code:
N=int(input())
alist=list(map(int,input().split()))

num_seq=0
for a in alist:
  if a==num_seq+1:
    num_seq+=1
    
if num_seq==0:
  print(-1)
else:
  print(N-num_seq)

Submission status: Accepted

Solution code:
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
if count:
    print(n - count)
else:
    print(-1)

Submission status: Accepted

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

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

Submission status: Accepted

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

r = 0
index = 0
ans = 0
for i in range(n) :
  r += 1
  for j in range(n) :
    if index >= n :
      break
    if a[index] == r :
      index += 1
      break
    ans += 1
    index += 1
      
if ans == n :
  print(-1)
else :
  print(ans)

Submission status: Accepted

Solution code:
N = int(input())
brick = list(map(int,input().split()))

def Break(n, lst):
  counter = 0
  cur = 1
  for i in range(len(lst)):
    if lst[i] == cur:
      cur += 1
    else:
      counter += 1
  if cur == 1:
    return -1
  return counter

print(Break(N, brick))

Submission status: Accepted

Solution code:
N = int(input())
arr = list(map(int, input().split()))
ans = 0
target = 1
for x in arr:
    if x == target:
        target += 1
    else:
        ans += 1

if ans == N:
    ans = -1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import itertools

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
now = 0

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

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