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:
import sys
input  = sys.stdin.readline


def solve():
    N = int(input())
    an = list(map(int,input().strip().split()))
    counter=1
    chk=False
    for i in range(N):
    	if counter == an[i]:
    		chk=True
    		counter+=1
    if chk:
    	print(N-counter+1)
    else:
    	print(-1)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n = int(input())

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

cnt = 0
ptr = 1

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def gcd(a, b):
  if a < b:
      a, b = b, a
  while a % b != 0:
      a, b = b, a % b
  return b


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

N = INT()
A = LIST()
c = 1
ans = 0
for i in range(N) :
  if A[i] == c:
    c += 1
    ans += 1

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

Submission status: Accepted

Solution code:
n  = int(input())
xs = [int(x) for x in input().split()]
c  = 0
y  = 1

for x in xs:
	if x == y:
		y += 1
	else:
		c += 1

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

cnt=1
ans=0
for i in range(N):
    if a[i]==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()))
cur = 0
ans = 0

for i in range(1, N+1):
    if cur >= N:
        break
    while cur < N and a[cur] != i:
        cur += 1
        ans += 1
    cur += 1
print(ans if N != ans else -1)

Submission status: Accepted

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


counter = 1
for i in A:
        if i == counter:
                counter += 1
                continue

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

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:
        num += 1
    else:
        count += 1

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

Submission status: Accepted

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

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

Submission status: Accepted

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

i = 0
c = 1
cnt = 0
while i < n:
    if input_list[i] == c:   
        c += 1
    else:
        cnt += 1     
        
    i += 1

print(cnt if c > 1 else '-1')

Submission status: Accepted

Solution code:
n = int(input())
a_list = map(int, input().split(' '))

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

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

Submission status: Accepted

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

x = 1
for ai in a:
    if ai == x:
        x += 1
if N-x+1 == N:
    print("-1")
else:
    print(N-x+1)

Submission status: Accepted

Solution code:
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    a = I()
    b = I()
    print(6 - a - b)
    return


# B
def B():
    n = I()
    s, t = input().split(' ')
    ans = []
    for i in range(n):
        ans.append(s[i])
        ans.append(t[i])
    print(''.join(ans))
    return


# C
def C():
    def GCD(a, b):
        if (b == 0):
            return a
        else:
            return GCD(b, a % b)

    a, b = LI()
    print(a * b // GCD(a, b))
    return


# D
def D():
    n = I()
    a = LI()
    cnt = 0
    for i in range(n):
        if a[i] == cnt + 1:
            cnt += 1
    if cnt == 0:
        print(-1)
    else:
        print(n - cnt)
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    D()
    return


# Solve
if __name__ == "__main__":
    D()

Submission status: Accepted

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

target=1
count=0

for i in ls:
    if i==target:
        target+=1
    else:
        count+=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()]
x=0
for i in range(n):
  if a[i]==x+1:
    x+=1
if x!=0:
  print(n-x)
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
        
if x == 1:
    print("-1")
else:
    print(n-x+1)

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

# longest increasing subsequence
def lis(li):
    lis_li = [li[0]]
    for i in li:
        if i > lis_li[-1]:
            lis_li.append(i)
        else:
            lis_li[bisect_left(lis_li, i)] = i
    return lis_li

rA = lis(A)

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

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

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

Submission status: Accepted

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

Submission status: Accepted

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

for item in A:
    if item != check_num:
        ans += 1
    else:
        check_num += 1
        
if ans == N:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

i = 1
c = 0
ans = 0

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

while c < N:
  if a[c] == i:
    i += 1
  else:
    ans += 1
  
  c += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    a=LIST()
    count = 1
    breakb = 0
    for i in range(n):
        if a[i]==count:
            count+=1
        else:
            breakb += 1
    if count==1:
        print(-1)
    else:
        print(breakb)
    
            
if __name__ == '__main__':
    do()

Submission status: Accepted

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

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

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

print(ans if ans < N else -1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys; readline = sys.stdin.readline
from collections import deque

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

j = 1

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

if j == 1:
    print(-1)
else:
    print(len(a) - (j - 1))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import collections
#sys.setrecursionlimit(100000)

n=int(input())
tmp = input().split()
s = list(map(lambda a: int(a), tmp))

ind=0
for i in range(n):
	if(s[i]==ind+1):
		ind+=1

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

Submission status: Accepted

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

count = 1
for i in a:
    if i == count:
        count +=1
if count-1 == 0:
    print(-1)
    exit()
# print(count-1)
print(N-count+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

count=0
for ai in aa:
  if ai == count+1:
    count+=1

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

Submission status: Accepted

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

tmp = 1
cnt = 0

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

Submission status: Accepted

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

cnt = 1
ans = 0
flg = False
for i in range(n):
    if cnt == a[i]:
        flg = True
        cnt += 1
    else:
        ans += 1
print(ans) if ans >= 0 and flg else print(-1)

Submission status: Accepted

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

count = 1
ans = 0
invalid = True

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[]
sum=0
for i in range(n):
    j=i+1-sum
    if a[i]!=j:
        sum+=1
    else:
        b.append(a[i])
def ans():
    if len(b)==0:
        print(-1)
        return
    for i in range(len(b)):
        if b[i]!=i+1:
            print(-1)
            return
    print(sum)
ans()

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
  if L[i] != target:
    breaknum += 1
  else:
    target += 1

if target != 1 and breaknum != 0:
  print(breaknum)
elif breaknum == n:
  print(-1)
else:
  print(0)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int,input().split()))
i = 0
j = 1
while i < N:
    x = a[i]
    if x == j:
        j += 1
    i += 1
ans = N - j + 1
if ans == N:
    ans = -1
print(ans)

Submission status: Accepted

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

#次に来て欲しい整数
hope_number = 1

#砕いた数
ans = 0

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

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

Submission status: Accepted

Solution code:
N=int(input())

str_list = input().split(' ')
a = [int(x) for x in str_list]

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

Submission status: Accepted

Solution code:
def solve():
    l=[0]
    count=0
    for i in a:
        if i==l[-1]+1:
            l+=[i]
        else:
            count+=1
    print(count if len(l)!=1 else -1)

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=1
c=0
for i in a:
  if i==s:
    s+=1
    c+=1

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

Submission status: Accepted

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

result = 0
pre_num = 0

for a in As:
    if a == pre_num+1:
        pre_num += 1
    else:
        result += 1

if pre_num == 0:
    result = -1

print(result)

Submission status: Accepted

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



def main():
    N = int(input())
    A = [int(x) for x in input().split()]

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

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




    


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n = int(readline())
a = list(map(int, read().split()))
ans = 0
cnt = 1
for a_ in a:
    if a_ == cnt:
        cnt += 1
    else:
        ans += 1


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

Submission status: Accepted

Solution code:
#coding:utf-8

n = int(input())
data = list(map(int, input().split(' ')))

i = 1
if 1 not in data:
    print(-1)
else:
    for num in data:
        if num == i:
            i += 1
    print(n - i + 1)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(input().split(" "))
an=0
co=1

for i in range(n):
    if int(a[i])==co:
        co+=1
    else:
        an+=1

if co==1:
    print("-1")
else:
    print(an)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
brick = [int(x) for x in input().split()]
if 1 not in brick:
  print(-1)
else:
  num, brk = 1, 0
  for i in range(N):
    if brick[i] == num:
      num += 1
    else:
      brk += 1
  print(brk)

Submission status: Accepted

Solution code:
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
x = 1
for i in range(n):
    if a[i]==x:
        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()))

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

Submission status: Accepted

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

now = 0
s = 1

ans = 0

while now != N:
    
    if s != a[now]:
        ans += 1
    else:
        s += 1
    
    now += 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
i=0
while i<n:
	if a[i]==count+1:
		count+=1
	i+=1
if count==0:
	print(-1)
else:
	print(n-count)

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 = count + 1

if count == 1:
  print('-1')
else:
  Ans = N - count + 1
  print(Ans)

Submission status: Accepted

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

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

n = n-1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

c = 1
ans = 0

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

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

Submission status: Accepted

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

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

index = 0
found = 0

for i in range(1, len_arr+1):
    try:
        index = arr.index(i, index)
        found += 1
    except ValueError:
        break

if found:
    print(len_arr - found)
else:
    print(-1)
exit(0)

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x)-1 for x in sys.stdin.readline().split()]

def main():
    N = I()
    A = LI()
    ans = 0
    cnt = 0
    cur = 0
    for i in range(N):
        if A[i] == cur:
            ans += cnt
            cnt = 0
            cur += 1
        else:
            cnt += 1
    if cur != 0:
        ans += cnt
    else:
        ans = -1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = map(int, input().split())

    ans, i = 0, 1
    for a in A:
        if a != i:
            ans += 1
        else:
            i += 1

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


main()

Submission status: Accepted

Solution code:
import math
import random
from operator import itemgetter
import re
import sys
from itertools import accumulate
from collections import defaultdict
from collections import deque
from bisect import bisect_left,bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
N = int(input())
S = [int(i) for i in input().split()]
num = 1
for i in range(N):
    if S[i] == num:
        num += 1
if num != 1:
    print(N-num+1)
else:
    print(-1)

Submission status: Accepted

Solution code:
n = int(input())

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

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

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

Submission status: Accepted

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    A = tuple(map(int, args[1].split()))

    ret = 0
    search = 1
    for i in range(n):
        if A[i] == search:
            search += 1
        else:
            ret += 1

    return str(ret if 1 < search else -1)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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:
from collections import Counter

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

next = 1
bricks = As

for i in range(n):
    if As[i] != next:
        bricks[i] = 0
    else:
        next += 1

ans = Counter(bricks)[0]

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

Submission status: Accepted

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

kosuu = 0
ima = 1

for a in A:
    if ima == a:
        ima += 1
        continue
    else:
        kosuu += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

i = 0
cnt = 0
while i < N:
    if a[i] == cnt + 1:
        cnt += 1
    i += 1
    
if cnt == 0:
    print(-1)
else:
    print(N - cnt)

Submission status: Accepted

Solution code:
n = int(input())
ls_a = list(map(int,input().split()))
cnt = 1
ans = 0
check = 0
for i in ls_a:
    if i == cnt:
        cnt+=1
    else:
        ans += 1
    if i == 1:
        check = 1
# print(cnt)
if check == 1:
    print(ans)
else:
    print(-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:
    cnt += 1
    continue
  
  num += 1
  
print(cnt if cnt != n else -1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]
ans = 0
c = 1
tmp = 0
if 1 not in a:
    print(-1)
    quit()
for i in range(N):
    if a[i] == c:
        ans += i - tmp
        c += 1
        tmp = i+1
    elif i == N-1:
        ans += i - tmp + 1
print(ans)

Submission status: Accepted

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

res = [0]
for x in a:
    if x == res[-1]+1:
        res.append(x)

ans = n - len(res) + 1

if res == [0]:
    ans = -1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#from fractions import gcd
#x = list(map(int, input().split()))
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:
    cnt =N+1
else:
    cnt -=1
print(N-cnt)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
need = 1

for i in a:
    if i == need:
        need += 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()))

s = 1

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
if min(a) > 1:
  print(-1)
  exit()

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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