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())
mx = 200000
mem = set()
a = list(map(int,input().split()))
num = [0 for _ in range(mx+1)]
for v in a:
    num[v]+=1
start = 1
idex = 0
while idex <n:
    if num[start]>0:
        while a[idex]!=start and idex<n:
            num[a[idex]] -=1
            idex+=1
        num[start]-=1
        idex+=1
        start+=1
    else:
        idex+=1
ans =(n-(start-1))
if ans <= n-1:
    print(ans)
else:
    print(-1)

Submission status: Accepted

Solution code:
n = int(input())

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


def solve():
  if 1 not in arr:
    print(-1)
    return

  cnt = 1
  for i in range(0, n):
    if arr[i] == cnt:
      cnt += 1
  print(n - (cnt-1))

def main():
  solve()


if __name__ == "__main__":
  main()

Submission status: Accepted

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

Submission status: Accepted

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


def solve():
    if A.count(1) == 0:
        return print(-1)

    number_possible = 1

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

    return print(N - number_possible + 1)


solve()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def solve(n, a_list):
    search = 1
    for i in range(n):
        if a_list[i] == search:
            search += 1
    if search == 1:
        return -1
    else:
        return n - search + 1


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    res = solve(n, a_list)
    print(res)


def test():
    assert solve(3, [2, 1, 2]) == 1
    assert solve(3, [2, 2, 2]) == -1
    assert solve(10, [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]) == 7
    assert solve(1, [1]) == 0


if __name__ == "__main__":
    test()
    main()

Submission status: Accepted

Solution code:
n = int(input())
li = list(map(int,input().split()))
num = 1
 
for i in range(n):
    if num==li[i]:
        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()))

count = 0
i = 0
d = 0
while i + d < len(a):
    if a[i + d] != i + 1:
        d += 1
        count += 1
    else:
        i += 1
if count < N:
    print(count)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
block = 1
for i in li:
    if i == block:
        block += 1
    else:
        ans += 1
if len(li) == ans:
    ans = -1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

a = list(map(int, input().split()))
index = 1
cnt = 0

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



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

Submission status: Accepted

Solution code:
N = int(input())
renga_list = [int(i) for i in input().split()]
now =1
count = 0
for i in renga_list:
    if i != now:
        count += 1
    else:
        now += 1
if now==1:
    print(-1)
else:
    print(count)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

count = 0
ix = 1
for i in li:
  if i != ix:
    count += 1
  else:
    ix += 1

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

Submission status: Accepted

Solution code:
def solve():
    N, *a = map(int, open(0).read().split())
    
    if 1 not in a:
        print(-1)
        exit()
    
    ans = 0
    target = 1
    i_tmp = -1
    for i, x in enumerate(a):
        if x == target:
            ans += i - i_tmp - 1
            i_tmp = i
            target += 1
    ans += N - i_tmp - 1
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

bb = 0
left = 0

for i in range(n):
    j = 0
    for j in range(left, n):
        # print(j)
        if la[j] == i+1:
            left = j + 1
            break
        else:
            bb += 1
    if j == n-1:
        break

if bb > n-1:
    print(-1)
else:
    print(bb)

Submission status: Accepted

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

num = 1
count = 0

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

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

Submission status: Accepted

Solution code:
def solve(lst):
    i = 1
    num_bricks = 0

    for num in lst:
        if num == i:
            num_bricks += 1
            i += 1
    
    if i == 1:
        return -1
    else:
        return len(lst) - num_bricks

N = input()
lst = list(map(int, input().strip().split(" ")))

print(solve(lst))

Submission status: Accepted

Solution code:
N = int(input())
alist = list(map(int, input().split()))
blist = []
alen = len(alist)

n = 0
i = 1

for a in alist:
    if a == i:
        i += 1
    else:
        blist.append(a)
        n += 1

if len(blist) == len(alist):
    print(-1)
else:
    print(n)

Submission status: Accepted

Solution code:
n=int(input())
la=input().split(" ")
l=[]
ans=0
c=1
for i in range(len(la)):
    l.append(int(la[i]))
for k in range(len(l)):
    if(l[k]==c):
        ans+=1
        c+=1
#print(ans,c)
if(ans==0):
    print(-1)
else:
    print(len(l)-ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import bisect
N=input()
seq=map(int, sys.stdin.readline().split())

LIS = [seq[0]]
for i in range(len(seq)):
    if seq[i]>LIS[-1]:
        LIS.append(seq[i])
    else:
        LIS[bisect.bisect_left(LIS, seq[i])] = seq[i]

l=-1 #長さ
for i,x in enumerate(LIS):
    if i+1==x:
        l=x

if l==-1:
    print -1
else:
    print N-l

Submission status: Accepted

Solution code:
n = int(input())						# 5
A =        list( map(int, input().split()) )	# 1 2 3 4 5 ...


NextNum=1
Crash=0
for _ in range(n):
	
	if A[_]==NextNum:
		NextNum += 1
	else:
		Crash+=1

ans=-1
if NextNum>1:
	ans = Crash

print(ans)

Submission status: Accepted

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

s = 1
break_count = 0
ans = 0
for a in A:
    if a == s:
        s += 1
        ans += break_count
        break_count = 0
    else:
        break_count += 1

ans += break_count

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

# print(N, block_list)

check_num = 1
K = 0
for i in range(N):
    if block_list[i] == check_num:
        K += 1
        check_num += 1

if K == 0:
    print(-1)    
else:
    print(len(block_list) - K)

Submission status: Accepted

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

criterion = 1
con = 0

L = []

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

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

Submission status: Accepted

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

start = 0
cnt = 0
for i in range(1, N+1):
  try:
    start = a.index(i, start)
  except:
    break
  else:
    cnt += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
i = 1
TF = "F"
for j in range(N):
    if A[j] == i:
        i += 1
        TF = "T"
i -= 1
if TF == "T":
    print(N-i)
else:
    print(-1)

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
else:
    if cnt == 0:
        ans = -1
    else:
        ans = len(a)-cnt

print(ans)

Submission status: Accepted

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

r = 1
torf = False

for i in range(n):
  if r == int(a[i]):
    r += 1
    torf = True

if torf:
  print(len(a) - (r - 1))
else:
  print(-1)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
rec = -1
for ai_str in input().split():
    ai = int(ai_str)
    if rec == -1:
        if ai == 1:
            rec = 1
    else:
        if rec + 1 == ai:
            rec = ai
if rec == -1:
    print('-1')
else:
    print(n - rec)

Submission status: Accepted

Solution code:
import sys
N=int(input())
a = sys.stdin.readline().split()
i=1
for num in a:
    if int(num) == i:
        i=i+1
if i != 1:
    print(N-i+1)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
now = 1
cnt = 0
flag = 2
if n == 1 and A[0] == 1:
    flag = 0
elif n == 1 and A[0] != 1:
    flag = 1
elif len(set(A)) == 1 and A[0] == 1:
    cnt = n -1
elif  len(set(A)) == 1 and A[0] != 1:
    flag = 1
elif 1 not in A:
    flag = 1
else:
    for a in A:
        if a == now:
            now += 1
        else:
            cnt += 1

if flag == 0:
    print(0)
elif flag == 1:
    print(-1)
else:
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
renga = int(input())

rengaList = input().split()
nowSearchRenga=1
cnt = 0
for i in range(renga):
  if int(rengaList[i]) == nowSearchRenga:
    nowSearchRenga=nowSearchRenga+1
    continue
  else:
    cnt=cnt+1
    
if i+1 == cnt:
  print(-1)
else:
  print(cnt)

Submission status: Accepted

Solution code:
import fractions
N = int(input())
A = list(map(int, input().split()))
find = 0
broken = 0

for i in range(N):
  if A[i] == find + 1:
    find = find + 1
  else:
    broken = broken + 1

if find == 0:
  print(-1)
else:
  print(broken)

Submission status: Accepted

Solution code:
ans = 0

n = input()
s = map(int, input().split())

now = 1

for i in s:
    if i == now:
        now += 1
    else:
        ans += 1


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

Submission status: Accepted

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

dp = [float('inf')] * N
rest = [0] * N
if nums[0] == 1:
    dp[0] = 0
    rest[0] = 1
else:
    dp[0] = 1
    rest[0] = 0

for i, num in enumerate(nums[1:], start=1):
    if rest[i - 1] + 1 == num:
        dp[i] = dp[i - 1]
        rest[i] = rest[i - 1] + 1
    else:
        dp[i] = dp[i - 1] + 1
        rest[i] = rest[i - 1]

if dp[-1] == N:
    print(-1)
else:
    print(dp[-1])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

else:
    print(-1)

Submission status: Accepted

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

flag = 0
cnt = 0
for i in numbers:
    if i == flag + 1:
        flag = i
    else :
       cnt += 1 

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

Submission status: Accepted

Solution code:
import sys

str = sys.stdin.readlines()

n = int(str[0])
alist_str = str[1].split()

target = 1
breaks = 0
for a in alist_str:
    if int(a) == target:
        target += 1
    else:
        breaks += 1

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

Submission status: Accepted

Solution code:
import sys

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

ans = 0
s = 1

for i in a:
    if i == s:
        s += 1
    else:
        ans += 1

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

Submission status: Accepted

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

standard = 1
counter = 0

for item in List:
  if item != standard:
    counter +=1
  else:
    standard +=1

if standard ==1:
  print(-1)
else:
  print(counter)

Submission status: Accepted

Solution code:
N = int(input())
lis = list(map(int,input().split()))
current = 0
ans = 0
positions = [-1]
for i in range(N):
  if lis[i] - current == 1:
    positions.append(i)
    current = lis[i]
if len(positions) == 1:
  print(-1)
else:
  if positions[len(positions)-1] == N-1:
    for j in range(len(positions)-1):
      ans += positions[j+1] - positions[j] - 1
    print(ans)
  else:
    positions.append(N)
    for g in range(len(positions)-1):
      ans += positions[g+1] - positions[g] - 1
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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:
import math

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!python3

def resolve():
    N = int(input().rstrip())
    a = list(map(int, input().rstrip().split(" ")))

    k = 0
    m = 1
    for x in a:
        if x == m:
            m += 1
            continue
        k += 1
    if len(a) == k:
        k = -1
    print(k)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

j = 1
count = 0

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

Submission status: Accepted

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

cnt = 0
sign = 1

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

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

Submission status: Accepted

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import fractions
from functools import reduce
from operator import mul
import bisect
import sys
import logging
import heapq
import itertools

logging.basicConfig(level=logging.ERROR)

input = sys.stdin.readline

setrecursionlimit(1000000)


def main():
	n = int(input())
	a = list(map(int,input().split()))
	if(1 not in a):
		print(-1)
		return
	c = 1
	for i in a:
		if(i==c):
			c+=1
	print(n-c+1)

def factorization(n):
	if n<2:
		return []
	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

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(numbers):
	return reduce(math.gcd, numbers)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

class PriorityQueue():
	def __init__(self):
		self.queue = []
	def push(self,i):
		heapq.heappush(self.queue,-i)
	def pop(self):
		return -1 * heapq.heappop(self.queue)
	def sum(self):
		return -sum(self.queue)

main()

Submission status: Accepted

Solution code:
N=int(raw_input())
A=[0 for i in range(N)]
s = raw_input().split()
for i in range(N):
    A[i] = int(s[i])

#print A

p = 0
n = 0
while (p < N):
    if A[p] == n+1:
        n = n+1
    p += 1

if n==0:
    print -1
else:
    print N-n

Submission status: Accepted

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

    count = 0
    pointer = 1
    for a_i in a:
        if a_i == pointer:
            pointer += 1
        else:
            count += 1

    if count == N:
        count = -1

    print(count)
        

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
data = list(map(int, input().split()))
now = 1
result = 0

if data.count(1):
    for i in range(n):
        if data[i] != now:
            result += 1
        else:
            now += 1
    print(result)
else:
    print(-1)

Submission status: Accepted

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

count=1
result=0

if 1 not in li:
  print(-1)
  exit()

for i in range(len(li)):
  if(li[i]==count):
    count+=1
  else:
    result+=1
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

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

if (counter == 0):
    print("-1")
else:
    print(N - counter)

Submission status: Accepted

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

S = {0}

for i, v in enumerate(A):
    S2 = set()
    for j in S:
        if v == i - j:
            S2.add(j)
        else:
            S2.add(j + 1)
    S = S2

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

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
check = True
ans = True
i = 0
j = 0
count = 0
while check:
    if a[j]==i+1:
        i += 1
        count = i
    j += 1
    if j==n:
        check = False

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

Submission status: Accepted

Solution code:
#coding:utf-8
n = int(input())
a = list(map(int, input().split()))
brick = []

#1が書いてあるレンガがない場合は解答なし
if 1 not in a:
    print('-1')
    exit()
else:
    num = 1
    for i in a:
        if i == num:
            brick.append(i)
            num += 1
#print(brick)
print(n-len(brick))

Submission status: Accepted

Solution code:
Num = int(input())

Str = input().split(" ")

NumList = [int(s) for s in Str]

Count = 0
Break = 1
for i in range(len(NumList)):
  if Break == NumList[i]:
    Break += 1
  else:
    Count += 1

if Count == Num:
  print("-1")
else:
  print(Count)

Submission status: Accepted

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

#print(A)

k=0
i=0
while n >i:
  if A[i] ==k+1:
    k +=1
  i +=1
if k==0:
  print(int(-1))
else:
  print(n-k)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
def isPossible(n):
    cnt = 1
    for a in A:
        cnt += (cnt == a)
    return n < cnt

if (1 not in A):
    print(-1)
else:
    lb = 0
    ub = 200100
    for i in range(25):
        if (ub-lb == 1): break
        mid = (lb + ub) // 2
        if isPossible(mid):
            lb = mid
        else:
            ub = mid
    print(N-lb)

Submission status: Accepted

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

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

Submission status: Accepted

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

i = 0
pointer = 1
cnt = 0
while i < N:
    if a[i] == pointer:
        pointer += 1
        cnt += 1
    i += 1

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

Submission status: Accepted

Solution code:
import collections
import math
import operator as op
from functools import reduce
import numpy as np
import math
import bisect


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


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

    a_pos = []
    n_breaks = 0
    i = 1
    for ai in a:
        if i - ai < 0:
            n_breaks += 1
        else:
            a_pos.append(ai)
            i += 1

    # a[i] - i >= 0 for all i

    # a_ret = []
    if len(a_pos) == 0 or a_pos[0] != 1:
        print(-1)
    else:
        i = 1
        for ai in a_pos:
            if i - ai != 0:
                n_breaks += 1
            else:
                # a_ret.append(ai)
                i += 1
        print(n_breaks)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

count=0
req = 1
if 1 not in a:
    print(-1)
else:
    for i in a:
        if i==req:
            req+=1
        else:
            count+=1
    print(count)

Submission status: Accepted

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


    if len(A) == 1 and A[0] == 1:
        print(0)
        exit()

    set_A = set(A)
    set_B = set()
    t = 1
    for i in range(1, len(A)):
        if not i in set_A:
            break
        if i in set_B:
            continue
        set_B.add(i)
        t += 1
    if t == 1:
        print(-1)
        exit()

    ans = 0
    tt = 1
    for a in A:
        if a == tt:
            tt += 1
            ans += 1
        else:
            pass

    print(len(A)-ans)

if __name__ == '__main__':
    main()

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:
        k+=1
    else:
        ans+=1
if k==1:print(-1)
else:print(ans)

Submission status: Accepted

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

count = 1

if 1 in a:
  ind = a.index(1)
  
  for i in range(ind,n):
    if a[i] == count+1:
      count += 1

  print(len(a) - count)
else:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# list = list(map(int, input().split()))

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

k = 1

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

ans = N - k + 1

if ans == N:
    ans = -1

print(ans)

Submission status: Accepted

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

C=1
M=0

for n in range(N):
  if int(A[n])!=C:
    M+=1
  else:
    C+=1
    
if M==N:
  M=-1

print(M)

Submission status: Accepted

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

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

if count == 1:
    print(-1)

else:
    print(ans)

Submission status: Accepted

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

cc = 1  # current_count
nuke_count = 0 # nuke no count

for a in A:
    if a == cc:
        cc += 1
    else:
        nuke_count += 1
        
if nuke_count == N:
    print('-1')
else:
    print(nuke_count)

Submission status: Accepted

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

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

Submission status: Accepted

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

c = 0
r = []
num = 1

for i in range(n):
    if a[i] == num:
        r.append(a[i])
        num += 1
    else:
        c +=1

if r == []:
    print(-1)
else:
    print(c)

Submission status: Accepted

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

Submission status: Accepted

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

num = 1
break_cnt = 0

for i in a:
    if i == num:
        num += 1
    else:
        break_cnt += 1
if n == break_cnt:
    print(-1)
else:
    print(break_cnt)