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:
n = int(input())
a = list(map(int, input().split()))

count = 0
c = 1
for i in range(n):
    if a[i] == c:
        c += 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()))
cnt = 0
i = 1
for a in A:
  if i == a:
    i += 1
  else:
    cnt += 1
print(cnt if cnt != N else -1)

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n = int(input())
aaa = get_nums_l()

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

Submission status: Accepted

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

count = 0

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

ans = N - count

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N = int(input())
a = list(map(int, input().split(" ")))
s = 1
count = 0
for i in range(len(a)):
    if a[i] == s:
        s += 1
    else:
        count += 1
if count == len(a):
    print(-1)
else:
    print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n=int(input())
    aa=list(map(int,input().split()))
    b=0
    i=1
    while True:
        try:
            j=aa.index(i,b)
        except ValueError:
            break
        b=j+1
        i+=1
    if i<=1:
        print(-1)
    else:
        print(n-i+1)

main()

Submission status: Accepted

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

t = 0
for i in range(n):
    if t + 1 == ai[i]:
        t += 1


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

Submission status: Accepted

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

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
t = int(input())
n = [ int(i) for i in input().split(" ") ]
 
count = 0
num = 1

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

if count == t:
  count = -1

print(count)

Submission status: Accepted

Solution code:
from numpy import *

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

count = 0

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

ans = N - count

if count == 0:
    ans = -1

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

index = 1
co = 0
for i in range(len(A)):
	if A[i] == index:
		index += 1
	else:
		continue

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

Submission status: Accepted

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

flg = False
nextval = 1
br = 0
for idx, a in enumerate(li_a):
    if a == nextval:
        nextval += 1
        flg = True
    else:
        br += 1
if flg:
    print(br)
else:
    print('-1')

Submission status: Accepted

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

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

Submission status: Accepted

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

A = []
i = 1
j = 0
while j != N:
    if a[j] == i:
        i += 1
    j += 1
else:
    if i == 1:
        print(-1)
    else:
        print(N-(i-1))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


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)

    divisors.sort()
    return divisors


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    A = Scanner.map_int()
    now = 1
    ans = 0
    for i in range(N):
        if now == A[i]:
            now += 1
        else:
            ans += 1
    ans = ans if ans != N else -1
    print(ans)

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
an = list(map(int, input().split()))
num = 1
listnum = len(an)
count = 0
for a in an:
    if a == num:
        count += 1
        num += 1
notnum = len(an) - count
if listnum == notnum:
    print(-1)
else:
    print(notnum)

Submission status: Accepted

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

x = 1
ans = 0
flag = False
for a in A:
    if a == x:
        x += 1
        flag = True
    else:
        ans += 1
if flag:
    print(ans)
else:
    print("-1")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if b_num == n:
    b_num = -1

print(b_num)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
N = int(input())
a = list(map(int, input().split()))

find=0
break_sum=0
cnt=0
for i in range(N):
    if a[i] == (find+1):
        break_sum+=cnt
        find+=1
        cnt=0
    else:
        cnt+=1
break_sum+=cnt
if min(a)!=1:
    break_sum=-1
print(break_sum)

Submission status: Accepted

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

if not 1 in a:
    print(-1)
else:
    p = a.index(1)
    target = 2

    for i in range(p, N):
        if a[i]==target:
            target += 1
    
    print(N-target+1)

Submission status: Accepted

Solution code:
N = int(input())
n_list = input().split(' ')
sort_list = []
t = 1
for num in n_list:
  if int(num) == t:
    sort_list.append(t)
    t += 1
if len(sort_list) == 0:
  print(-1)
else:
  print(N - len(sort_list))

Submission status: Accepted

Solution code:
from sys import stdin, stdout
N = int(stdin.readline())
brick = list(map(int, stdin.readline().split()))

cont = 0
for i in range(N):
    if brick[i] == cont+1:
        cont = cont+1

if cont == 0:
    stdout.write("-1\n")
else:
    stdout.write("%d\n" % (N-cont))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = 0
for i in aa:
	if ans + 1 == i:
		ans+=1
if 0 == ans:
	print(-1)
else:print(N-ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

c = -1
b = 1
ans = 0
for i in a:
    if b == i:
        if i == 1:
            c = 1
        b += 1
    else:
        ans += 1

if c == -1:
    ans = -1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
for i in range(len(a) - 1, -1, -1):
    if a[i] == 1:
        cntnum = 2
        num = 1
        for j in range(i + 1, len(a)):
            if a[j] == cntnum:
                num += 1
                cntnum += 1
        print(n - num)
        exit()

print(-1)

Submission status: Accepted

Solution code:
n=int(input())
tmp=[int(x) for x in input().split()]
cnt=0
num = []
i = 0
for j in range(n):
  if i+1 == tmp[j]:
    num.append(tmp[j])
    i+=1
  else:
    cnt+=1

print(cnt if num!=[] else -1)

Submission status: Accepted

Solution code:
N=int(input())
L=list(map(int,input().split()))
ANS=0
FLG=-1
CNT=1
for i in L:
  if i == CNT:
    FLG=0
    CNT+=1
  else:
    ANS+=1
if FLG != -1:
  print(ANS)
else:
  print(-1)

Submission status: Accepted

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

cnt = 1
br = 0

for i in a:
    if i == cnt:
        cnt += 1
    else:
        br += 1

if br == n:
    br = -1

print(br)

Submission status: Accepted

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

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

print(n - flag + 1 if 1 in a else -1)

Submission status: Accepted

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


def solve(nums):
    cnt = 0
    num = 1
    if 1 not in nums:
        return -1

    for i in range(n):
        if nums[i] == num:
            num += 1
        else:
            cnt += 1
    return cnt if cnt > 0 else 0


print(solve(nums))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(n, A):
    num, count = 0, 0
    for a in A:
        if a == num + 1:
            num += 1
        else:
            count += 1
    return count if num > 0 else -1

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
numList = list(map(int, input().split()))
i = 0
temp = 1
counter = 0
while True:
    if numList[i] == temp:
        temp += 1
        counter += 1
    i += 1
    if i == N:
        break
if counter == 0:
    print(-1)
else:
    print(N - counter)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:





def main():
    n = int(input())
    al = list(map(int, input().split()))

    #print(n)
    #print(al)

    #print(len(al))

    cnt = 1
    bl = []
    for ai in al:
        if ai == cnt:
            bl.append(ai)
            cnt += 1
    b_cnt = len(al) - len(bl)
    if(cnt == 1):
        print(-1)
    else:
        print(b_cnt)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

"""考え方
左から、小さい順に数字を取得する。
これで得られる最大の値とレンガの個数の差分が答え。
ただし、「1」が無い場合は「-1」となる。
"""

pre_num = 0
for n in range(0,N,1):
  if A[n] == pre_num+1:
    pre_num = A[n]

if pre_num == 0:
  ans = -1
else:
  ans = N - pre_num

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split(" ")]
c = 0
ind = 1
for i in a:
    if i==ind:
        ind += 1
    else:
        c += 1
if n == c:
    print(-1)
else:
    print(c)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
n=int(input())
a=[int(x) for x in input().split()]
crashed=0
i=1
for ai in a:
    if ai==i:
        i+=1
    else:
        crashed+=1
if crashed==n:
    crashed=-1
print(crashed)

Submission status: Accepted

Solution code:
"""TLE
N = int(input())
A_list = list(map(int, input().split()))
i = 0
while(True):
    try:
        if A_list[i] != i+1:
            del A_list[i]
        else:
            i += 1
    except:
        if A_list == []:
            print(-1)
        else:
            print(N-len(A_list))
        exit()
"""

N = int(input())
A_list = list(map(int, input().split()))
iirenga = 1
kudaita = 0
for i in range(N):
    if A_list[i] == iirenga:
        iirenga += 1
    else:
        kudaita += 1
if kudaita == N:
    print(-1)
    exit()
print(kudaita)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
c = 0
for i in range(n):
  if a[i] != i+1-c:
    c += 1
if c < n:
  print(str(c))
else:
  print(-1)

Submission status: Accepted

Solution code:
N = int(input())
li = [int(zz) for zz in input().split()]

count = 1
ans = 0
ind = 0
while ind < N:
    if li[ind] == count:
        count += 1
        ans += 1
    ind += 1

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

Submission status: Accepted

Solution code:
n = int(input())
list_a = list(map(int, input().split()))
list_a_complete = []
k = 1
ans = -2

for i in range(n):
    if list_a[i] == k:
        list_a_complete.append(k)
        k += 1

if len(list_a_complete) == 0:
    ans = -1

else:
    ans = len(list_a) - len(list_a_complete)

print(ans)

Submission status: Accepted

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

s = 1
ans = 0

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

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

Submission status: Accepted

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

start = 1

for num in nums:
    if num != start:
        continue
    start += 1

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
mark = 1
ans = N
pena = 1
for i in range(N):
    if A[i] == mark:
        pena = 0
        mark += 1
        ans -= 1
if pena == 1:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

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

def main():
    n = ni()
    a = na()

    cur = 1
    cnt = 0
    is_ok = False
    for aa in a:
        if aa == cur:
            is_ok = True
            cur += 1
        else:
            cnt += 1
    if is_ok:
        print(cnt)
    else:
        print(-1)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
d = 1
c = 0

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

Submission status: Accepted

Solution code:
N=int(input())
L=input().split()
L=list(map(int,L))
count=0
i=1

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

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

Submission status: Accepted

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

i = 1

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

print(N - target + 1)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if 1 not in A:
    print(-1)
    exit()
bef=1
ans=0
for i in A:
    if i==bef:
        bef+=1
    else:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split(" ")))

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

    print(count if count != len(a) else -1)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import os

def main():
    count = int(input())
    list_num = list(map(int, input().split()))
    result_list = []
    if not(1 in list_num):
        print("-1")
    else:
        num = 1
        for i in list_num:
            if num == i:
                result_list.append(num)
                num += 1
        print(len(list_num) - len(result_list))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def t(a):
    b = [False] * len(a)
    c = 1
    for i, j in enumerate(a):
        if j == c:
            b[i] = True
            c += 1

    return b.count(False) if any(b) else -1


if __name__ == '__main__':
    n = input()
    a = list(map(int, input().split()))
    print(t(a))

Submission status: Accepted

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

prev = 1
crash = 0

if not 1 in a:
  print("-1")
else:
  for i in range(N):
    if a[i] == prev:
      prev += 1
    else:
      crash += 1
  else:
    print(crash)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import floor, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
a = LIST()

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

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

Submission status: Accepted

Solution code:

# Beginners Contest (D)

import sys

# 入力取得
input()
n_ls = [int(e) for e in input().split(" ")]

# 探索
satisfy_n = 0
crush_n = 0
for n in n_ls:
	if n == (satisfy_n+1):
		satisfy_n += 1
	else:
		crush_n += 1

# 結果出力
if satisfy_n == 0:
	print(-1)
else:
	print(crush_n)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a_list = list(map(int, input().split()))

search_num = 1
count = 0

for i in range(n):
    if a_list[i] == search_num:
        search_num = search_num + 1
        count = count + 1

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

Submission status: Accepted

Solution code:
N = int(input())
block_list = list(map(int,input().split()))
blocked_list = []

cnt = 1
break_cnt = 0

for i in range(N):
    if block_list[i] == cnt:
        blocked_list.append(cnt)
        cnt += 1

    else:
        break_cnt += 1


if blocked_list == []:
    print(-1)

else:
    print(break_cnt)

Submission status: Accepted

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

Submission status: Accepted

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

res = 0
crr = 1
for a in a_list:
    if a == crr:
        crr += 1
    else:
        res += 1

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

    print(n - cnt + 1)

Submission status: Accepted

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