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:
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):

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

    if count == 1:
        print(-1)
    else:
        print(N - count + 1)
    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())
cnt = 0
A = list(map(int,input().split()))
ex = 1
for i in range(len(A)):
    if ex != A[i]:
        cnt += 1
    else:
        ex += 1
if cnt == len(A):
    print(-1)
else:
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
if 1 not in a:
    print(-1)
    exit()
cur = 0
for val in a:
    if val == cur + 1:
        cur += 1
print(n - cur)

Submission status: Accepted

Solution code:
N = int(input())

List=list(map(int,input().split()))
cnt = 1
ck = 0

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

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

Submission status: Accepted

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

c = 0

flag = False

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

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

Submission status: Accepted

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

def main():
    N = int(input())
    rengas = [int(s) for s in input().split()]
    focus = 1
    count = 0
    for renga in rengas:
        if renga == focus:
            focus += 1
        else:
            count += 1
    result = count if count < len(rengas) else (-1)
    print(result)

if __name__ == "__main__":
    main()

Submission status: Accepted

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


count = 1
ans = 0
for a in A:
    if count == a:
        ans += 1
        count += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
l=1
cnt=0
for i in range(N):
    if A[i]!=l:
        cnt+=1
    else:
        l+=1
if cnt==N:
    print(-1)
else:
    print(cnt)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
cnt=1
for i in range(n):
  if a[i]==cnt:
    cnt+=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()))
ans = 1
attack = 0
for i in range(n):
    if a[i] != ans:
        attack += 1
    else:
        ans += 1
if attack == n:
    print(-1)
else:
    print(attack)

Submission status: Accepted

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


show_flg = True
show_flg = False


def main():
    N = I()
    a = LI()
    ans = 0
    temp = []

    for i in range(N):
        if len(temp) == 0 and a[i] == 1:
            temp.append(1)
        elif len(temp) != 0 and a[i] == temp[-1] + 1:
            temp.append(a[i])
        else:
            ans += 1

    # print(temp)
    if len(temp) == 0:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

B = [i for i in range(1,N+1)]

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

if index == 0:
    print('-1')
else:
    print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def main():
    _ = int(input())
    a = list(map(int,input().split()))
    if 1 in a:
        x = 1
        ans = 0
        for i in a:
            if x == i:
                x += 1
            else:
                ans += 1
        print(ans)
    else:
        print(-1)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
if __name__ == "__main__":
	N = int(input())
	a = list(map(int, input().split()))
	ans = 0
	num = 1
	flag = False
	for i in range(N):
		if num == a[i]:
			num += 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
index = 1

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

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

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
    else:
        continue
if count==0:
    print(-1)
else:
    print(n-count)

Submission status: Accepted

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

K = 0
for num in A:
    if num == K+1:
        K+=1

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans = 0
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:
import sys,collections,math,random;sys.setrecursionlimit(10**7)
from fractions import gcd
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n =I()
lis = Is()
i = 1
for e in lis:
    if e == i:
        i += 1
if i == 1:
    print(-1)
else:
    print(n-i+1)

Submission status: Accepted

Solution code:
import sys
N = int(input())
A = [int(i) for i in input().split()]
if not 1 in A:
    print(-1)
    sys.exit()
tmp = 1
cnt = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 1
ans = 0

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

print(ans if cnt > 1 else -1)

Submission status: Accepted

Solution code:
from fractions import gcd

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def solve(N, A):
    current_brick = 1
    break_count = 0
    for i in range(N):
        if current_brick == A[i]:
            current_brick += 1
        else:
            break_count += 1
    if break_count == N:
        return -1
    return break_count


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N = inputInt()
	A = inputList()

	ans = 0
	tmp = 1
	for i,val in enumerate(A):
		if val == tmp:
			tmp += 1
		else:
			ans += 1

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

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import sys, math
from collections import defaultdict
from copy import deepcopy
import itertools
input = sys.stdin.readline
# 文字列の場合は普通のinput()を使うか下を使う
# input = sys.stdin.readline().rstrip()


N = int(input())
A = [0] + list(map(int, input().split()))
s = 0
destroyed = 0
for i in range(N + 1):
    if A[i] == s:
        s += 1
    else:
        destroyed += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if A.count(1)==0:
    print(-1)
    exit()
x=1
for i,a in enumerate(A):
    if a==x:
        x+=1


print(N-x+1)

Submission status: Accepted

Solution code:
N = input()

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

# left = []
left_count = 1
count = 0

for a in A:
    if a == left_count:
        left_count += 1
    else:
        count += 1
if left_count > 1:
    print(count)
else:
    print(-1)

Submission status: Accepted

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

    if 1 not in A:
        return -1

    most_left_one = A.index(1)
    ans = most_left_one
    current = 1
    for i in range(most_left_one, N):
        if current == A[i]:
            current += 1
        else:
            ans += 1
    return ans

print(d_brick_break())

Submission status: Accepted

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

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

if find:
    print(N-target+1)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

N = int(input().split()[0])
a_list = list(map(int, input().split()))
x_list = []
max_a = 0
for i in range(N):
    a = a_list[i]
    if a == max_a + 1:
        max_a += 1
ans = N - max_a if max_a != 0 else -1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
L = list(map(int, input().split()))
counter = 1
br = 0
import sys
if 1 not in L:
  print(-1)
  sys.exit()

for num in L:
  if num != counter:
    br += 1
  if num == counter:
    counter += 1
print(br)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

count = 1
ans = 0
for a in a_list:
    if a != count:
        ans += 1
    else:
        count += 1

if(count == 1):
    ans = -1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N=int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

K = 0
for ai in a:
    if ai == K + 1:
        K += 1
print(N - K if K > 0 else -1)

Submission status: Accepted

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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    target = 1
    ans = 0
    for a in A:
        if a == target:
            target += 1
        else:
            ans += 1
    if ans == N:
        print(-1)
        return
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
cnt = 0
now = 0
for x in a:
	if x == now+1:
		now+=1
		continue
	cnt+=1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

n_break = 0
target = 1
nums = map(int, input().split(" "))

for num in nums:
    if num == target: 
        target += 1
    else:
        n_break += 1

if n_break == n:
    out = -1
else:
    out = n_break
print(out)

Submission status: Accepted

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

ans = 0
j = 0

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

if j == 0:
    ans = -1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

i = 1
r = 0
while r < N:
  if A_list[r] == i:
    i += 1
    r += 1
  else:
    r += 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()))
ans = -1

if a.count(1) == 0:
    print(ans)
    exit()

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

print(N - (index - 1))

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
cur = 1
last = 0

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

    print(ans + last)

Submission status: Accepted

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

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

print(ans if ans < N else -1)

Submission status: Accepted

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

cnt = 1
ans = 0
for ai in a_list:
    if ai == cnt:
        cnt += 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()))

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

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

Submission status: Accepted

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

Submission status: Accepted

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

count = 1
ans = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
br = list(map(int, stdin.readline().rstrip().split()))
cur = 0
for i in br:
    if i == cur + 1:
        cur = i
if cur == 0:
    print(-1)
else:
    print(n - cur)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np

def main():
	n=int(input())
	A=list(map(int,input().split()))
	cnt=1
	
	for i in A:
		if i==cnt:
			cnt+=1
	cnt-=1
	
	ans=len(A)-cnt
	
	if cnt==0:
		ans=-1
	print(ans)
	
	




	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

index = 1
ans = 0
flag = 0
for i in range(1,N+1):
  if A[i-1] == index:
    flag = 1
    index += 1
  else:
    ans += 1

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

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

cnt = 0
for a in A:
    if a == 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()))

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

Submission status: Accepted

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

ans = 0
checker = 1

for a in A:
    if a == checker:
        checker += 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()
l = 0
cur = 1
for i in range(N):
    if A[i] == cur:
        cur += 1
        l += 1
print(N - l)

Submission status: Accepted

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

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

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

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

search = 1
cnt = N
for a in As:
    if a == search:
        search += 1
        cnt -= 1

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

i = 0
answer = 0

while answer + i < N:
    if A[answer+i] == i:
        i += 1
    else:
        answer += 1

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

count = 0
num = 1
for brick in bricks:
  if brick != num:
    count += 1
  else:
    num += 1
    
print(count if count != len(bricks) else -1)

Submission status: Accepted

Solution code:
import fractions as fc

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

rans = 0
tmp = 1
for i in range(N):
    if A[i] == tmp:
        rans += 1
        tmp += 1

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

Submission status: Accepted

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

counter = 1

ans = 0

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

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

Submission status: Accepted

Solution code:
import sys
from fractions import *

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

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

Submission status: Accepted

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

i = 1
b = 0

for ai in an:
    if ai == i:
        i += 1
    else:
        b += 1

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

Submission status: Accepted

Solution code:
n = int(input())
A = [int(i) for i in input().split()]

tmp = 1
ans = 0

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

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

Submission status: Accepted

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

table = collections.defaultdict(int)
m = 0
for i in range(N):
    table[a[i]] += 1
    if a[i] == m or a[i] == m+1:
        m = a[i]
if m == 0:
    print(-1)
else:
    print(N - m)

Submission status: Accepted

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

Submission status: Accepted

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

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




if __name__ == "__main__":
    main()

Submission status: Accepted

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

temp = 1

count = 0

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

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

Submission status: Accepted

Solution code:
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

import itertools

#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

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

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

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

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


def main():
#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]
    n=int(input())
    a=list(map(int,input().split()))
    count=0
    temp=1
    for i in range(n):
        if a[i]==temp:
            temp+=1
        else:
            count+=1
    if count>=n:
        print(-1)
    else:
        print(count)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N=int(input())
ai=input().split(" ")
a=[]
for i in range(N):
  a+=[int(ai[i])]
#print(a)
want=1
bk=0
for i in range(N):
  if a[i]==want:
    want+=1
  else:
    bk+=1

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