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:


from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n = ii()
    a = li()

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

    
main()

Submission status: Accepted

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


cur = 1
ans = 0

for i in a:
    if i != cur:
        ans += 1
    elif i == cur:
        cur += 1

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

Submission status: Accepted

Solution code:
n = int(input())
l = list(map(int, input().split()))
if not 1 in l:
  print(-1)
  exit()
cnt = 1
ans = 0
for item in l:
  if item == cnt:
    ans += 1
    cnt += 1
print(n - ans)

Submission status: Accepted

Solution code:
import bisect

INF = 1 << 30

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

ans = 0
now = 1

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

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

Submission status: Accepted

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

if a==(list(i+1 for i in range(N))):
       print(0)
       exit()

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

Submission status: Accepted

Solution code:
count,ans,point = 1,0,0
n = int(input())
t = list(map(int,input().split()))
for i,j in enumerate(t):
	if j == count:
		ans += i - point
		point = i + 1
		count += 1
if not point == n:
	ans += n - point
if count == 1:
	try:
		t.index(1)
	except:
		ans = -1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

c=0
z=1
f=0

for i in range(0,N):
  if a[i]!=z:
    c+=1
  else:
    f=1
    z+=1
if f==0:
  print("-1")
else:
  print(c)

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0
cur = 1
for x in A:
    if x == cur:
        cur += 1
    else:
        cnt += 1

print(cnt if cnt != len(A) else -1)

Submission status: Accepted

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

for i in range(0,l):
  if a[i] != m:
    n+=1
  elif a[i] == m:
    m+=1

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

judge = False
count = 0
for i in range(N):
    if nums[i] == count+1:
        count += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#abc148d

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

Submission status: Accepted

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

num,pt,n_pt,count = 1,-1,0,0
while n_pt < len(A):
    if A[n_pt] == num:
        count += n_pt - pt -1
        pt = n_pt
        num += 1
    n_pt += 1
if pt != -1:
    count += len(A) - pt -1
    print(count)
else:
    print(-1)

Submission status: Accepted

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

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

Submission status: Accepted

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

ret = 0
cursor = 1

for a in A:
  if a != cursor:
    ret += 1
  else:
    cursor += 1
    
if ret < N:
  print(ret)
else:
  print(-1)

Submission status: Accepted

Solution code:
n = int(raw_input())
a = map(int,raw_input().split())
c = 0
for i in xrange(n):
  if a[i] == c+1:
    c += 1
res = n-c
if res == n:
  print -1
else:
  print res

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
count = 0
position = 0
while position < N:
  for j in range(1,N+1):
    for i in range(position,N):
      if A[i] == j:
        count = count + 1
        position += 1
        break
      else:
        position = position + 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

counts = 1
counters = 0
for x in a:
    if(x == counts):
        counts += 1
    else:
        counters += 1

if(counts == 1):
    print(-1)
    exit()
print(counters)

Submission status: Accepted

Solution code:
N = int(input())

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

max_no = 0
cnt_break = 0

for i in list_num:
  if i == max_no + 1:
    max_no = i
    continue
  cnt_break = cnt_break + 1


if max_no == 0:
  print(-1)
else:
  print(cnt_break)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    a = inputIntList()
    ans = 0
    look = 1
    for i in a:
        if look == i:
            look += 1
        else:
            ans += 1

    return ans if ans != N else -1


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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))[::-1]

ans = 0
i = 1
while len(a):
    ai = a.pop()
    if ai == i:
        i += 1
    else:
        ans += 1
if i == 1:
    ans = -1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))[::-1]

if len(a) == 1 and a[0] == 1:
    ans = 0
else:
    ans = 0
    i = 1
    while len(a):
        ai = a.pop()
        if ai == i:
            i += 1
        else:
            ans += 1
    if i == 1:
        ans = -1
print(ans)

Submission status: Accepted

Solution code:
x=int(input())
a=list(map(int,input().split()))
k=0
lol=[]
for i in a:
    if i==k+1:
        k+=1
        lol.append(i)
if len(lol)>0:
    print(x-k)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
now = 1 
for i in range(N):
	if now == A[i]:
		now += 1 
if now == 1 :
  	print(-1)
else:
	print("{}".format(N - now + 1))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

from fractions import gcd

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


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

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
track = 1

for i in range(n) :
	if cnt!=1 :
		if arr[i]!=track :
			arr[i] = -1
		else :
			track+=1
			cnt = 1
	else :
		if arr[i] == track :
			track+=1
		elif arr[i] == track - 1 :
			continue
		else:
			arr[i] = -1



res = set(arr)

# print(res)

if -1 in res :
	res.remove(-1)

ans = n - len(res)

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

Submission status: Accepted

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

if min(a) >= 2:
        print(-1)
        exit()

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

M = 2

for i in range(k+1, N):
    if a[i] != M:
        count += 1
    else:
        M+= 1
        

print(count)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n = int(input())
li = list(reversed(list(map(int, input().split()))))
li_a = []
a = 1
c = 0
while c<n:
  c += 1
  b = li.pop()
  if b == a:
    a += 1
if a == 1:
  print(-1)
else:
  print(n-a+1)

Submission status: Accepted

Solution code:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
a = MAP()

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


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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

# code here
n = int(input().strip())
A = map(int, input().strip().split())

s = 1
c = 0

for a in A:
    if a == s:
        s += 1
    else:
        c += 1

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

Submission status: Accepted

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


def correct():
    N = int(input())
    list_a = [int(a) for a in input().split()]

    nxt = 1
    ans = 0
    for a in list_a:
        if a == nxt:
            nxt += 1
        else:
            ans += 1
    if ans == N:
        ans = -1

    print(ans)


if __name__ == "__main__":
    correct()

Submission status: Accepted

Solution code:
def hantei(n,data):
    v = 1

    for st in data:
        if st == v:
            v = v + 1

    if v == 1:
        return -1
    else:
        return n - v + 1

n = int(input())
data = [int(x) for x in input().split()]

print(hantei(n,data))

Submission status: Accepted

Solution code:
def mainFunc():
    N = int(input())
    arr = list(map(int, input().split(" ")))
    K = 1

    for i in range(len(arr)):
        if K == arr[i]:
            K += 1
    
    if K == 1:
        print(-1)
    else:
        print(N - K + 1)

mainFunc()

Submission status: Accepted

Solution code:
import sys

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

n = ni()
a = na()

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


print(n-x+1 if x > 1 else -1)

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v

def comb(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 bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


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

    if min(A) != 1:
        print(-1)
        return

    c = 1
    ans = 0

    for a in A:
        if a == c:
            c += 1
        else:
            ans += 1
    
    print(ans)

main()

Submission status: Accepted

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

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:
n = int(input())
# a,b = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
count = 1
for i in a:
    if count == i:
        ans += 1
        count += 1

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

Submission status: Accepted

Solution code:
N = int(input())
X = tuple(map(int, input().split()))

c = 0
for x in X:
    if x == c+1:
        c+=1
if c == 0:
    ans = -1
else:
    ans = N-c
print(ans)

Submission status: Accepted

Solution code:
n = int(raw_input())
bricks = raw_input().split()
bricks = [int(i) for i in bricks]
smash = 0
result = []
pos = 1
if 1 not in bricks:
  smash = -1
else:
  for i in bricks:
    if i == pos:
      pos = pos+1
    else:
      smash = smash + 1
print smash

Submission status: Accepted

Solution code:
_,a=open(0)
i=1
c=0
for a in a.split():f=int(a)!=i;c+=f;i+=f^1
print(-(i<2)or c)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(-1 if v==1 else N-v+1)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans, c = 0, 1
for a in A:
    if a == c:
        c += 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 = 1
for i in range(n):
    if a[i] == cnt:#すねけさんが満足するレンガの砕き方は1,2,3...となってるのが前提なので1の後には2が2の後には3が存在しないとダメ
        cnt += 1
if cnt == 1:
    print(-1)
    exit()
print(n-cnt+1)#cntを1で初期化してるので+1をする

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
i = k = 0
try:
  while True:
    i = a.index(k + 1, i) + 1
    k += 1
except ValueError:
  print(n-(k or n+1))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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)
    exit()
print(n-cnt+1)

Submission status: Accepted

Solution code:
n = int(input())
brick = list(map(int,input().split()))
k = 1
ans = 0
flag = True
for i in range(n):
    if brick[i] == k:
        k += 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()))
tar=1
found=0
for i in range(len(a)):
  if a[i]==tar:
    tar+=1
    found+=1
if found==0:
  print(-1)
else:
  print(N-found)

Submission status: Accepted

Solution code:
n = int(input())

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

ans=0
for i in range(n):
    if a[i] + ans != i+1:
        ans+=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
key = 1

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

Submission status: Accepted

Solution code:
import numpy as np
i8 = np.int64


def solve(a):
    x = 1
    res = 0
    for i in range(a.shape[0]):
        if a[i] == x:
            x += 1
        else:
            res += 1
    return res


def main():
    stdin = open('/dev/stdin', 'rb')
    pin = np.fromstring(stdin.read(), i8, sep=' ')
    n = pin[0]
    a = pin[1:]
    ans = solve(a)
    if ans == n:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans=0
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:
import sys

read = sys.stdin.read
N, *a = map(int, read().split())

cnt = 0
idx = 1
for i in a:
    if i == idx:
        cnt += 1
        idx += 1
        

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

Submission status: Accepted

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

x = 1

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

print(n - x + 1 if x > 1 else -1)

Submission status: Accepted

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

S=0
ans =-1
x=1

if 1 in A:
    ans = 0
    for i in A:
        if i ==x :
            x += 1
    ans = N - x +1
            
print(ans)

Submission status: Accepted

Solution code:
#D
n = int(input())
v = list(map(int, input().split()))
cnt = 1
for i in v:
    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()))
S = 1
for i in range(N):
  if A[i] == S:
    S += 1
if S == 1:
  print(-1)
else:
  print(N - S + 1)

Submission status: Accepted

Solution code:


def resolve():
    N=int(input())
    c=1
    cc=0
    A=[int(i) for i in input().split()]
    for i in A:
        if c==i:
            c+=1
        else:
            cc+=1
    print(cc if cc!=N else -1)



if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

target_number=1

for i in range(N):
  if(numbers[i]==target_number):
    target_number+=1
  
if(target_number>1):
  print(N-target_number+1)
  
elif(target_number==1):
  if(1 in numbers):
    print(N-1)
  else:
    print(-1)

Submission status: Accepted

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

tar = 1
for a_ in A:
    if a_ == tar:
        tar += 1
tar -= 1

if tar:
    print(N - tar)
else:
    print(-1)

Submission status: Accepted

Solution code:
import numpy as np

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

nxt = 1
ans = 0

for data in x:
	if nxt == data:
		nxt += 1
	else:
		ans += 1
if ans == N:
	ans = -1

print(ans)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
 
n = int(readline())
num = 1
res = 0
for i in readline().split():
  if num != int(i):
    res += 1
  else:
    num += 1
if res == n:
  print(-1)
else:
  print(res)

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
now=1
cnt=0
for i in l:
  if i==now:
    now+=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()))
count = 0
num = 1

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

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

Submission status: Accepted

Solution code:
N = int(input())
ori = [int(i) for i in input().split()]
count = ori.count(1)
if count == 0:
    print(-1)

else:
    savepoint = 0
    for j in range(1,N+1):
        for i in range(savepoint,N):
            if ori[i] == j:
                savepoint = i
                #print(savepoint)
                #print(j,i)
                sub = j
                break
        if i == N-1:
            break
    print(N-sub)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input())
a_list = list(map(int,input().split()))
count = 0
i = 1

if not 1 in a_list:
    print("-1")
    exit()

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

print(len(a_list)-count)

Submission status: Accepted

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

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

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

    else:
        smash += 1

print(smash)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


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

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

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # 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:
count = 1
destroy = 0
N = int(input())
List=list(map(int,input().split()))
isSuccess = False

if len(List) == 1:
  if List[0] == 1:
    print(0)
  else:
    print(-1)
else:
  for i in range(N):
    if List[i] != count:
      destroy += 1
    else:
      count += 1
      isSuccess = True
  if isSuccess == False:
    print(-1)
  else:
    print(destroy)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
l=[0]*200005
n=int(input())
a=[0]+list(map(int,input().split()))
l[0]=1
for i in range(1,n+1):
    if l[a[i]-1]==1:
        l[a[i]]=1

res=n
for i in range(1,n+1):
    res-=l[i]

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

Submission status: Accepted

Solution code:
from sys import stdin


n = int(stdin.readline().rstrip())
arr = [int(x) for x in stdin.readline().rstrip().split()]

rslt = []

ex = 0
cntr = 1
bb = 0

for a,j in enumerate(arr):
    if j == cntr:
        cntr += 1
    else:
        bb += 1


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

Submission status: Accepted

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

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

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

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

print(N-ans+1)

Submission status: Accepted

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

X = 1
broken = 0

if  1 not in brick_nums:
    print(-1)

else:
    for i in range(N):
        if X == brick_nums[i]:
            X += 1
        else:
            broken += 1
        
    print(broken)

Submission status: Accepted

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

Submission status: Accepted

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

ans=0
now=1

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

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

Submission status: Accepted

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

    try:
        most_left_one = A.index(1)
    except ValueError:
        return -1  # 1 が見当たらなければ満足できない

    ans = most_left_one  # 1 より左のレンガはすべて砕く
    current_searching = 1
    for a in A[most_left_one:]:
        if current_searching == a:
            current_searching += 1
        else:
            ans += 1
    return ans

print(d_brick_break())

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import*
n,*a=map(int,open(0).read().split())


def main():
  
  if 1 not in a:
    print(-1);exit()

  b=deque(a)
  #print(b)

  i=1
  cnt=0
  while True:

    if len(b)==0:
      break

    if b[0]!=i:
      cnt+=1
      b.popleft()

    else:#b[0]==i
      cnt+=0
      b.popleft()
      i+=1

    #print(b,cnt)

  print(cnt)

  
main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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


for i in range(N-1):
    if A[i]==ne:
        c+=1
        ne+=1
if A[-1]==ne:
    c+=1
print(N-c)

Submission status: Accepted

Solution code:
N = int(input())
li = [int(i) for i in input().split()]
ans = -1
el = 1
sum = 0
for i in range(N) :
    if li[i] == el :
        el+=1
        sum+=1
de = N - sum
if de != N :
    ans = de
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans, nxt = 0, 1

for i in range(N):
  if a[i] == nxt:
    nxt += 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()))
g = 0
cnt = 1
for i in range(N):
    if cnt == a[i]:
        cnt += 1
    else:
        g += 1
if cnt == 1:
    print(-1)
else:
    print(g)

Submission status: Accepted

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