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 collections import deque
N = int(input())
A = [int(x) for x in input().split()]
d = deque()
for i in range(N):
    d.append(A[i])
ans = 0
index = 1
if min(A) != 1:
    print(-1)
else:
    for i in range(N):
        left = d.popleft()
        if left == index:
            index += 1
        else:
            ans += 1
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

N, = map(int, input().split())
# N = int(input())
L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

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

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

Submission status: Accepted

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

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

if sx > 1:
    print(delcnt)
else:
    print(-1)

Submission status: Accepted

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y
 
N=II()
xs=LI()
 
cur = 1
idx = 0
res = 0
for x in xs:
    if x == cur:
        cur += 1
    else:
        res += 1
if cur != 1:
    print(res)
else:
    print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
xs=LI()

cur = 1
idx = 0
res = 0
for x in xs:
    if x == cur:
        cur += 1
    else:
        res += 1
if cur != 1:
    print(res)
else:
    print(-1)

Submission status: Accepted

Solution code:
n = int(input())
l = list(input().split())

target_num = 1
for i in range(n):
  if target_num == int(l[i]):
    target_num += 1
  else:
    target_num = target_num

if target_num == 1:
  print("-1")
else:
  print(n - target_num +1)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
cur = 1
for brick in bricks:
    if brick != cur:
        ans += 1
    else:
        cur += 1

if cur == 1:
    ans = -1

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from sys import stdin
import fractions

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
# print(N)
# print(A)
nex = 1
ans = 0

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
 
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
  if a[i] == 1:
    break
  else:
    pass
else:
  print("-1")
  sys.exit()
j = 1
for i in range(n):
  if a[i] == j:
    j += 1
  else:
    pass
print(str(n-j+1))

Submission status: Accepted

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

Submission status: Accepted

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

for a in A:
    if a == search:
        rev_ans += 1
        search += 1
ans = N - rev_ans
if rev_ans == 0:
    ans = -1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# D
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=int)

count = 0
index = 1
for i in range(N):
    if A[i] == index:
        index+=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()))

now = 0
for x in a:
    if x == now + 1:
        now = x

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

Submission status: Accepted

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

Submission status: Accepted

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

count = 1
k = 0       #break time

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

if k == n:
    k = -1

print(k)

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

Submission status: Accepted

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

    return N, renga


def solve(N, renga):
    ans = -1
    # print(renga)
    count = 0
    for i in range(N):
        if renga[i]==count+1:
            count+=1


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


if __name__ == '__main__':
    N, renga = read()
    # print("%d" % solve(N, renga))
    solve(N, renga)

Submission status: Accepted

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

curr = 1
for ai in a:
    if ai == curr:
        curr += 1

if curr == 1:
    print -1
else:
    print len(a) - curr + 1

Submission status: Accepted

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

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

searching_for = 1
for e in l:
    if searching_for == e:
        searching_for += 1
    else:
        c+=1

print(c)

Submission status: Accepted

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

key=1

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

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

Submission status: Accepted

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

def sol(N,a):
    nex = 1
    con = 0

    if  not 1 in a:
        return -1
    for i in range(N):
        if nex == a[i]:
            nex +=1
        else:
            con +=1
    return con
        
print(sol(N,a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
p = 1
res = 0
for i in range(N):
  if a[i] == p:
    p += 1
  else:
    res += 1
if res == N:
  print(-1)
  exit(0)
print(res)

Submission status: Accepted

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


num=1
break_num=0

for i in L:
    if i!=num:
        break_num+=1
    else:
        num+=1

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

Submission status: Accepted

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

ans = n
for x in a:
    if x == k:
        k += 1
        ans -= 1

if ans == n:
    ans = -1

print(ans)

Submission status: Accepted

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

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
    else:
        i += 1
if cnt == n:
    print(-1)
else:
    print(cnt)

Submission status: Accepted

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

d = collections.defaultdict(list)
for index, num in enumerate(AL):
    d[num].append(index)

ans = 0
if not d[1]:
    print(-1)
else:
    current_pos = d[1][0]
    ans = 0
    for i in range(1, N+1):
        a = d[i+1]
        index = bisect.bisect_right(a, current_pos)
        if index != len(a):
            current_pos = a[index]
            continue
        else:
            ans = i
            break
    print(N - ans)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    c = 0
    t = 1
    for i in range(n):
        if a[i] == t:
            c += 1
            t += 1
    print(n - c if c != 0 else -1)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
INF = float("inf")#無限大の設定1
IINF = 10 ** 18#無限大の設定2
MOD = 10 ** 9 + 7#まれに用いるmodを予め設定しておく
n = int(stdin.readline().rstrip())
ax = list(map(int, stdin.readline().rstrip().split()))

a = 1
i = 0
ans = 0
lim = True
while lim:
    if ax[i] != a:
        i += 1
        ans += 1
    else:
        i += 1
        a += 1
    if i == n:
        lim = False
    else:
        pass
if ans == n:
    print(-1)
else:
    print(ans)

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())
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())
a = list(map(int, input().split()))

start = 1
i = 0
while i < n:
    if a[i] == start:
        start += 1
        i += 1
    else:
        i += 1

start -= 1

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

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

Submission status: Accepted

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

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

stair = 1
cnt = 0

for i in list : 
    if i == stair : 
        stair += 1
    else : 
        cnt += 1
        
if stair == 1 : 
    print(-1)
else : 
    print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

currnum = 1
breaknum = 0

for num in nums:
  if num == currnum:
    currnum = currnum + 1
    continue
  breaknum = breaknum + 1

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

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

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
j, ans = 1, 0
for i in a:
    if i==j: j+=1
    else: ans+=1
print(ans if j!=1 else -1)

Submission status: Accepted

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

Submission status: Accepted

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

current = 0
order = 1
destroy = 0
while current < N:
    if bricks[current] == order:
        order += 1
    else:
        destroy += 1
    current += 1
else:
    print(destroy) if destroy < N else print(-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def run(N, a):
    ans = -1
    cnt = 0
    idx = 0
    i = 1
    match = False
    while idx < N:
        ai = a[idx]
        idx += 1
        if ai == i:
            # print('match', i, ai, idx)
            match = True
            i += 1
        else:
            # print('break', i, ai, idx)
            cnt += 1
    if match:
        ans = cnt
    return ans


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions

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

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

    if i == 1:
        print(-1)
    else:
        print(n-i+1)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n):
    if a[i] == ans +1: ans +=1
if ans == 0: print(-1)
else: print(n - ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

result = 0
for i in range(N):
    if a[i] != (i-result):
        result += 1

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

Submission status: Accepted

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

for i in range(n):
    if lst[i]==count:
        count+=1

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

Submission status: Accepted

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

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

Submission status: Accepted

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

i = 0
j = 0
bt = 0

while i < n:
  while j < n - i:
    if a[i+j] == i+1:
      bt += 1
      break
    if j + i == n-1:
      if i == 0:
        bt = -1
      j = n + 1
      i = n + 1
      
    j += 1
  i += 1
  
if bt != -1:
  bt = n - bt
  
print(bt)

Submission status: Accepted

Solution code:
n = int(input())
arra = input().split(' ')
for i in range(len(arra)):
    arra[i] = int(arra[i])
j = 1
num = 0
oldlen = len(arra)

buf =[0] * oldlen
for i in range(oldlen):
    if arra[i] != j:
        num += 1
        buf[i] = 1
    else:
        j += 1
for i in range(oldlen-1, -1, -1):
    if buf[i] == 1:
        del arra[i]
newlen = len(arra)
if newlen == oldlen:
    print(0)
elif num == oldlen:
    print(-1)
else:
    print(num)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
length = int(input())
ary = [int(i) for i in input().split(' ')]

size = 0
for i in ary:
  if i == size + 1:
    size += 1
if size == 0:
  print(-1)
else:
  print(length - size)

Submission status: Accepted

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

num = 1
ans = 0

for i in A:
    if i == num:
        num += 1
    else:
        ans += 1

if num == 1:
    print('-1')
else:
    print(str(ans))

Submission status: Accepted

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


if m == [i+1 for i in range(n)]:
    print(0)
elif 1 not in m:
    print(-1)
else:
    target = 1
    for i in m:
    
        if i == target:
            ans += 1
            target += 1

    print(n-ans)

Submission status: Accepted

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

num =  1
ans = 0
if 1 not in a:
    print(-1)
    sys.exit()
for i in a:
    if i == num:
        num += 1
    else:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
p=int(input())
k=input().split()
i2=1
i=0
while i<p:
    if i2==int(k[i]):
        i2+=1
    i+=1
if(i2==1):
    print(-1)
else:    
 print(p-(i2-1))

Submission status: Accepted

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

current = 0;

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

Submission status: Accepted

Solution code:
import sys

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

number = 1
count = 0

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

for num in nums:
    if num == number:
        number += 1
    else:
        count += 1
print(count)

Submission status: Accepted

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

cnt = 0
num = 1

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

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(input().split())
num=1
count=0

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":

    length = int(input())
    dataset = [int(x) for x in input().split()]
    last = dataset[-1] 

    pop_list = []
    i=0
    breaks=0
    for x in dataset:
        if x == i+1:
            i += 1
        else:
            breaks +=1
    
    if breaks>0 and i==0:
        print(-1)
    else:
        print(breaks)

Submission status: Accepted

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

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

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+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()))
ans = 0
c = 1
if 1 not in A:
    print(-1)
    exit()
for e in A:
    if e == c:
        ans += 1
        c += 1
print(N-ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from math import ceil
from math import factorial
from collections import Counter
from operator import itemgetter
import bisect
ii = lambda: int(input())
iia = lambda: list(map(int,input().split()))
isa = lambda: list(input().split())
def gcd(a,b):
	if(b==0):
		return a
	return gcd(b,a%b)

n = ii()
a = iia()
x = 1
c = 0
for i in a:
	if(x==i):
		x+=1
	else:
		c+=1
if(c==n):
	c=-1
print(c)

Submission status: Accepted

Solution code:
N = int(input())
l = list(map(int, input().split()))
if l == [i+1 for i in range(N)]: # 1, 2, 3, ...
  print(0)
elif 1 not in l:
  print(-1)
else:
  detected = 0
  target = 1
  for i in l:
    if i == target:
      detected += 1
      target += 1
  
  print(N - detected)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def inp():
 return [int(x) for x in input().split()]

N = int(input())
a = inp()

n = 1
i = 0 

k = 0

while i<N:
  while i<N and a[i]!=n:
    i+=1
    k+=1
  i+=1
  n+=1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
brick = list(map(int, input().split()))
cnt = 0
i = 0
j = 1
while i < n:
    if brick[i] == j:
        cnt += 1
        j += 1
    i += 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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve(n, a):
    t = 1
    for x in a:
        if x == t:
            t += 1
    return -1 if t == 1 else n + 1 - t

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

Submission status: Accepted

Solution code:
n=int(input())
A=list(map(int,input().split()))
#print(A)
f=0
g=1
for i in range(0,n):
    if A[i]!=g:
        f+=1
    else:
        g+=1
#printf("%d %d\n",f,g)
if g!=1:
    print(f)
else:
    print(-1)

Submission status: Accepted

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

cnt = 0
num = 1
for i in range(len(li)):
    if li[i] != num:
        cnt += 1
    else:
        num += 1

if len(li) != cnt:
    print(cnt)
else:
    print(int(-1))

Submission status: Accepted

Solution code:
from collections import deque

N = int(input())
li = deque(list(map(int, input().split())))

ans = N
num = 1
for i in range(N):
  ind = li.popleft()
  if ind == num:
    ans -= 1
    num += 1
    
if N == ans : ans = -1

print(ans)

Submission status: Accepted

Solution code:
N = input()
num_list = input().split()

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

if cnt ==0:
    print(-1)
else:
    print(len(num_list)-cnt)

Submission status: Accepted

Solution code:
input()
nums = list(map(int, input().split()))
 
cnt = 0
cur = 1
 
for i in nums:
    if i == cur:
        cur+=1
    else:
        cnt+=1
if cur == 1:
    print(-1)
else:
    print(cnt)

Submission status: Accepted

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

cnt = 0
cur = 1

for i in nums:
    if i == cur:
        cur+=1
    else:
        cnt+=1
if cur == 1:
    print(-1)
else:
    print(cnt)

Submission status: Accepted

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

index = 1
bre = 0
for a in As:
	if index == a:
		index += 1
	else:
		bre += 1
else:
	if N != bre:
		print(bre)
	else:
		print("-1")

Submission status: Accepted

Solution code:
n = int(input())
z = input().split(" ")

look_for = 1
breaks = 0

for i in z:
    if int(i) == int(look_for):
        look_for += 1
        continue
    breaks += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list()

A = [n for n in map(int, raw_input().split())]
    
st = 1
num_brk = 0

for a in A:
    if a == st:
        st += 1
    else:
        num_brk += 1

if num_brk == N and st == 1:
    print '-1'
else:
    print '{}'.format(num_brk)

Submission status: Accepted

Solution code:
N = int(input())
S = input().split()
a = list(map(int,S))
count = 1
broken = 0
flag = False

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

if flag :
  print(N - broken)
else :
  print(-1)

Submission status: Accepted

Solution code:
def main():

    n = int(input())
    A = list(map(int, input().split()))
    cnt = 0
    start = 1
    for i in range(len(A)):
        if A[i] != start:
            cnt += 1
        else:
            start += 1

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

    cnt = 0
    cur_num = 0
    for elem in a:
        if elem == cur_num + 1:
            cur_num += 1
        else:
            cnt += 1
    
    ans = 0
    if cur_num == 0:
        ans = -1
    else:
        ans = cnt
    
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
n = int(input())
data = [int(s) for s in input().split()]
ini = 1
indData = []
for i in range(len(data)):
  if data[i] == ini:
    ini += 1
    indData.append(i)
ans = 0
if len(indData) == 1:
  if len(data) == 1:
    print(0)
    exit()
  else:
    print(len(data) -1)
    exit()
if len(indData) == 0:
  print(-1)
  exit()
for i in range(len(indData)-1):
  ans += indData[i+1] - indData[i] -1

ans += indData[0]
print(ans)
#print(indData)

Submission status: Accepted

Solution code:
#d-brick break
n=int(input())
num=list(map(int,input().split()))

x=1
ans=0
for i in num:
    if x==i:
        x+=1
    elif x != i:
        ans+=1

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

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

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

Submission status: Accepted

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