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 itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys

sys.setrecursionlimit(100000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline-------------------------------------------- 
    n = int(input())
    a = list(map(int,input().split()))
    keep = 1
    cnt = 0
    for i in range(n):
        if a[i] == keep:
            cnt += 1
            keep += 1
    print(n - cnt if cnt != 0 else -1)
            



if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

Solution code:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
A = read_ints()
now = 1
for a in A:
    if a == 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()))

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

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:
import queue
import math
import copy
"""
N = int(input())
#S = input()
# (N,M) = (int(i) for i in input().split(" "))
# A = [int(i) for i in input().split()]
A = []
for i in range(N):
	A.append(int(input()))

print(A)

"""

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

cur = 1
for a in A:
	if cur == a:
		cur += 1
b = N-cur+1
if b == N:
	print(-1)
else:
	print(b)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if 1 in a:
    pass
else:
    print("-1")
    sys.exit()

i=1
retval=0
for ai in a:
    if ai==i:
        i+=1
    else:
        retval+=1

print(retval)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

ans = 0
#nums = [i for i in range(1,N+1)]
cur = 1
for i in range(N):
    if A[i]==cur:
        cur += 1

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

Submission status: Accepted

Solution code:
n = int(input())
num = [ int(v) for v in input().split() ]

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

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

Submission status: Accepted

Solution code:
def bbreak(n, s):
    ans = 0
    pnt = 1
    for b in s:
        if b == pnt:
            pnt += 1
        else:
            ans += 1
    if pnt == 1:
        print('-1')
    else:
        print(ans)

if __name__ == "__main__":
    import sys
    in_str = []
    for line in sys.stdin:
        in_str.append(line)
    bbreak(int(in_str[0]), [int(_) for _ in in_str[1].split()])

Submission status: Accepted

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

crush = 0
target = 1
for n in range(N):
    if(a_list[n] != target):
        crush += 1
    else:
        target += 1
if(crush == N):
    crush = -1
print(crush)

Submission status: Accepted

Solution code:
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict

sys.setrecursionlimit(10**7)
N = int(input())
a = list(map(int, input().split()))

cnt = 1
for ai in a:
    if ai == 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()))
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:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

num = 1
ok = 0
for a in As:
    if a == num:
        num += 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()))
count = 1
for i in a:
    if i == count:
        count += 1
if count == 1:
    print(-1)
else:
    print(N-(count-1))

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
no = 1
for A in As:
    if A == no:
        no += 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()))

broken_bricks = 0
count = 1
for ai in a:
    if ai == count:
        count += 1
    else:
        broken_bricks += 1

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

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
if 1 in A:
    cnt = 0
    ans = 0
    for i in A:
        if i == cnt + 1:
            ans += 1
            cnt += 1
    print(N-ans)
    
else:
    print(-1)

Submission status: Accepted

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

st=1
for i in range(n):
    if lis[i]==st:
        st+=1
if st==1:
    print(-1)
else:
    print(int(n+1-st))

Submission status: Accepted

Solution code:
# 2019/12/22

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

ctr=1

bricks=N

for i in range(N):
	if(a[i]==ctr):
		ctr+=1
		bricks-=1

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

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
c = 1
i = 0
while i < len(a):
    try:
        i = a.index(c,i)
        c += 1
    except:
        break
if c == 1:
    print(-1)
else:
    print(len(a)-c+1)

Submission status: Accepted

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

print(ans)

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:
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
now = 1
count = 0
flag = 0
for i in range(len(li)):
    if li[i] == 1:
        flag = 1
    if li[i] == now:
        now += 1
    else:
        count += 1
if flag == 0:
    print(-1)
    exit()
else:
    print(count)

Submission status: Accepted

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

cnt = 1
flag = 0

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

Submission status: Accepted

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

e = 1  # 次ほしい数字
k = 0  # 砕く
for ai in A:
    if ai == e:
        e += 1
    else:
        k += 1

if e == 1:
    print(-1)
else:
    print(k)

Submission status: Accepted

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

N = int(input())
count = 0
prenumber = 1
a = [int(i) for i in input().split()] 

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

if prenumber == 1:
    print(-1)
else:
    print(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 tmp == a[i]:
        tmp += 1
    else:
        cnt += 1
if cnt < N:
    print(cnt)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

num = 0

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

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

Submission status: Accepted

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

ans = 0
cnt = 1

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

if cnt == 1 and ans > 0:
    ans = -1

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = [int(x) for x in input().split()]
j = 1
if 1 not in a:
    print(-1)
    sys.exit()
for i in range(N):
    if a[i] == j:
        j += 1
print(N - j + 1)

Submission status: Accepted

Solution code:
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

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

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

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

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys, fractions
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
l = list(map(int, input().split()))
ans = 0
num = 1
for i in range(N):
    if l[i]==num:
        num += 1
    else:
        ans += 1
if num==1:
    print(-1)
else:
    print(ans)

Submission status: Accepted

Solution code:
words = lambda t : list(map(t, input().split()))
n = int(input())
xs = words(int)


cnt = 1
for i in range(n):
    if xs[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()))
index = float('inf')
cnt = 1
for i in range(n):
    if a[i] == 1:
        index = i
        break
if index == float('inf'):
    print(-1)
    exit()
for i in range(index, n):
    if a[i] == cnt:
        cnt += 1
cnt -= 1
print(n - cnt)

Submission status: Accepted

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

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

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

for e in a:
    if e == num:
        num += 1

if num == 1:
    ans = -1
else:
    ans = n - num + 1

print(ans)

Submission status: Accepted

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

INVALID = -1


def compute(n, bs):
    # zero-based
    cs = [b - 1 for b in bs]
    num_breaks = 0
    cur_pos = 0
    for c in cs:
        if c == cur_pos:
            cur_pos += 1
        else:
            num_breaks += 1
    if num_breaks == n:
        return None
    else:
        return num_breaks


def main():
    n = int(input())
    bs = [int(b) for b in input().split()]
    res = compute(n, bs)
    if res is None:
        print(-1)
    else:
        print(res)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

now = 1
cnt = 0
for a in A:
  if now != a:
    cnt += 1
  else:
    now += 1

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

Submission status: Accepted

Solution code:
import sys
from fractions import gcd

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

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

Submission status: Accepted

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

Submission status: Accepted

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

c = 1
for i in range(n):
  if c == ls[i]:
    c += 1
    
print(n-c+1 if c>1 else -1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
An = input().split(' ')

reach_num = 0
for a in An:
    if int(a) == reach_num + 1:
        reach_num += 1
if reach_num == 0:
    print(-1)
else:
    print(N - reach_num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

num = 1
count = 0

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

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

Submission status: Accepted

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

ans_tmp = 0
targ = 1
for i, ai in enumerate(a):
    if ai == targ:
        ans_tmp += 1
        targ += 1

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

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] == cnt+1 :
    cnt += 1

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
'''

sekai_no_owari
 愛

''' 

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

Submission status: Accepted

Solution code:

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    now = 0
    for i in range(N):
        if A[i]==now+1:
            now +=1
        else:
            pass
    if now == 0:
        print(-1)
    else:
        print(N-now)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
d = defaultdict(list)
dp = [-1]*N

for i in range(N):
    if a[i]==1:
        dp[i] = 1
    else:
        if len(d[a[i]-1])==0:
            continue

        dp[i]=dp[d[a[i]-1][-1]]+1
    
    d[a[i]].append(i)

ans = 10**18

for i in range(N):
    if dp[i]==-1:
        continue
    
    ans = min(ans, N-dp[i])

if ans==10**18:
    print(-1)
else:
    print(ans)

Submission status: Accepted

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

i = 1
cnt = 0
for a in A:
    if (a == i):
        cnt += 1
        i += 1

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from fractions import gcd

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    res = 0
    i = 1
    for a in A:
        if i == a:
            i += 1
        else:
            res += 1

    if res == N:
        res = -1
    return str(res)

if __name__ == '__main__':
    print(solve())

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

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

now = 1
ans = N
for i in A:
    if now == i:
        now += 1
        ans -= 1

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

from bisect import bisect_left

N = I()
a = III()

d = defaultdict(list)
for i in range(N):
    d[a[i]].append(i)

now = 0
ans = N
for i in range(1,N+1):
    p = bisect_left(d[i], now)
    if p<=len(d[i])-1:
        now = d[i][p]
        ans -= 1
    else:
        if i==1:
            print(-1)
            exit()
        break

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

def main():
    x = 1
    for i in range(n):
        if a[i] == x:
            x += 1
    
    ans = n - (x - 1)
    return -1 if ans == n else ans

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

for i in range(n):
    if a[i] == temp[-1] + 1:
        temp.append(a[i])

# print(temp)

if len(temp) > 1:
    print(n - len(temp) + 1)
else:
    print(-1)

Submission status: Accepted

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

ans = 0
tmp = 1
for a in A:
  if a == tmp:
    tmp += 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()))

i = 1
ans = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
res=1
my_bool=False
for i in a:
    if i==res:
        my_bool=True
        res+=1

if my_bool:
    print(n-res+1)
else:
    print(-1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


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

    c = 0
    for i in a:
        if i == c + 1:
            c += 1

    print(n - c if c else -1)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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