Problem:


Score : 400 points

Problem Statement

We have N bricks arranged in a row from left to right.

The i-th brick from the left (1 \leq i \leq N) has an integer a_i written on it.

Among them, you can break at most N-1 bricks of your choice.

Let us say there are K bricks remaining. Snuke will be satisfied if, for each integer i (1 \leq i \leq K), the i-th of those brick from the left has the integer i written on it.

Find the minimum number of bricks you need to break to satisfy Snuke's desire. If his desire is unsatisfiable, print -1 instead.

Constraints

All values in input are integers.

1 \leq N \leq 200000

1 \leq a_i \leq N

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

Print the minimum number of bricks that need to be broken to satisfy Snuke's desire, or print -1 if his desire is unsatisfiable.

Sample Input 1

3
2 1 2

Sample Output 1

1

If we break the leftmost brick, the remaining bricks have integers 1 and 2 written on them from left to right, in which case Snuke will be satisfied.

Sample Input 2

3
2 2 2

Sample Output 2

-1

In this case, there is no way to break some of the bricks to satisfy Snuke's desire.

Sample Input 3

10
3 1 4 1 5 9 2 6 5 3

Sample Output 3

7

Sample Input 4

1
1

Sample Output 4

0

There may be no need to break the bricks at all.



Sample input:
3
2 1 2


Sample output:
1

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    a = list(map(int, input().split()))
    count = 1
    ans = 0
    for i in range(N):
        if a[i] == count:
            count += 1
            continue
        else:
            ans += 1

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

number = 0
now_i = 1
one_flag = False
for a in A:
    if a != now_i:
        number += 1
    else:
        now_i += 1
        one_flag = True

if one_flag is False:
    print('-1')
else:
    print(number)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

found = []
for n in range(N):
    if a[n] == len(found) + 1:
        found.append(a[n])

print(N - len(found) if len(found)!=0 else -1)

Submission status: Accepted

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

Submission status: Accepted

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

count=1

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

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

print(abs(count-1-n))

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

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

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

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

Submission status: Accepted

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

n = int(readline())
c = 1
r = 0
p = 0
a = True
for i, j in enumerate(readline().split()):
  if c != int(j):
    continue
  else:
    a = False
    c += 1
    r += i - p
    p = i + 1
if a:
  print(-1)
else:
  print(r + n - p)

Submission status: Accepted

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

num = 1
ans = -1
for i in lst:
  if (num == i):
    num += 1
if (num-1 != 0):
  ans = N-num+1
print(ans)

Submission status: Accepted

Solution code:
import bisect
def main():
    N = int(input())
    a = list(map(int, input().split()))
    d = {}
    for i, v in enumerate(a):
        if v in d:
            d[v].append(i)
        else:
            d[v] = [i]
    t = -1
    r = 0
    if 1 not in d:
        return -1
    for i in range(1, N+1):
        if i not in d:
            r += N - 1 - t
            break
        j = bisect.bisect_left(d[i], t)
        if j == len(d[i]):
            r += N - 1 - t
            break
        r += d[i][j] - t - 1
        t = d[i][j]
    return r
print(main())

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC148 D
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
a=nl()
cur=1
ans=0

b=set(a)

if 1 in b:
    pass
else:
    print(-1)
    exit()

flg=True
for i in range(n):
    if i==a[i]:
        pass
    else:
        flg=False

if flg:
    print(0)


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

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 N-count+1 < N:
    print(N-count+1)
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:
    num+=1
  else:
    cnt+=1
if 1 in A:
  print(cnt)
else:
  print(-1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


def fetch_one_line():
    return stdin.readline().rstrip()


def fetch_int_input():
    return [int(s) for s in fetch_one_line().split()]


def fetch_inputs(times):
    return [fetch_one_line() for _ in range(times)]


def fetch_int_inputs(times):
    return [[int(s) for s in fetch_one_line()] for _ in range(times)]

fetch_one_line()
nums = fetch_int_input()
now_num = 1
remove_num = 0

for n in nums:
    if n == now_num:
        now_num += 1
    else:
        remove_num += 1


if now_num == 1:
    remove_num = -1

print(remove_num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def acinput():
    return list(map(int, input().split(" ")))


N=int(input())

a=acinput()

cnt=0
now=1
for i in range(N):
   # print(i)
    if now==a[i]:
        #print(now,a[i])
        now+=1
        

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

Submission status: Accepted

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

tmp=0
for i in l:
    if i==tmp+1:
        tmp+=1

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

Submission status: Accepted

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

a_min = 1
cnt = 0
for a in a_n:
    if a == a_min:
        a_min = a + 1
    else:
        cnt += 1

if cnt == len(a_n):
    print(-1)
else:
    print(cnt)

Submission status: Accepted

Solution code:
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    A = LIST()

    check = False
    cnt = 1
    for i, a in enumerate(A):
        if a == cnt:
            check = True
            cnt += 1

    print(N - cnt + 1 if check else -1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

manzoku=1
hakai = 0
for i in range(N):
    if bricks[i] == manzoku:
        manzoku += 1
    else:
        hakai += 1

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

Submission status: Accepted

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

start = 1
broke = 0
for i in range(N):
    if array[i] != start:
        broke += 1
    else:
        start += 1

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
"""
data=[set() for i in range(N)]
for i in range(N):
    data[A]
"""

count=0
for a in A:
    if a==count+1:
        count+=1
if count:
    print(N-count)
else:
    print(-1)

Submission status: Accepted

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

now = 0
for i in range(0, n):
    if int(array[i]) == now+1:
        now += 1

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

Submission status: Accepted

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

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

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

if s == 0:
    print('-1')
else:
    print(n - s)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
num=1
start=0
while(start != -1):
    try:
        start=a.index(num,start)
        num+=1
    except ValueError:
        break
num-=1
#print(n,num)
if(num>0):
    print(n-num)
else:
    print(-1)

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

count = 1
ans = 0
for num in nums:
    if num != count:
        ans += 1
    else:
        count += 1

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

Submission status: Accepted

Solution code:
input()

lst = map(int, input().split())

count = 0
current = 1
find = False
for i in lst:
  if i == current:
    current += 1
    find = True
  else:
    count += 1
if find:
  print(count)
else:
  print(-1)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# coding:utf-8

N = int(input())
bricks = [a for a in map(int, input().split(' '))]
start = False
pre = 0
ans = 0

for brick in bricks:
    if not start:
        if brick == 1:
            start = True
            pre = 1
        else:
            ans += 1
    else:
        if brick == pre + 1:
            pre += 1
        else:
            ans += 1

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

Submission status: Accepted

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

counter = N - 1
current = 1

for a in A:
    # print(f"a={a} counter={counter}, current={current}")
    if a == current:
        current += 1
    else:
        counter -= 1
    if counter < 0:
        print(-1)
        break
else:
    print(N - counter -1)

Submission status: Accepted

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

next_int = 1
num_break = 0

for x in A:
    if x == next_int:
        next_int += 1
        continue
    num_break += 1

result = -1 if next_int == 1 else num_break
print(result)

Submission status: Accepted

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

x = {}
min_value = 1
is_found = False
for i in range(n):
    if a[i] == min_value:
        min_value += 1
        is_found = True

if is_found:
    print(n - (min_value - 1))
else:
    print(-1)

Submission status: Accepted

Solution code:

n = int(input())
lis = list(map(int, input().split()))
temp = 1
for i in range(n):
    if lis[i] == temp:
        temp += 1

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

Submission status: Accepted

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

# 左からn番目の初期値
check = 1
for i in range(n):
    # 同じなら壊さず次の数を探す
    if a[i] == check:
        check += 1
    # 違ったら壊す
    else:
        a[i] = 0

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# 煉瓦の個数N
N = int(input())

A = list(map(int, input().split()))
# 砕いた後の煉瓦数 K

cost = 0
cnt = 1
# i番目の数字がiだと嬉しい
for a in A:
    # index番号の不一致
    if a != cnt:
        # 壊すして次へ
        cost +=1
        
    # index番号が一致していたら、次のindex番号を比較
    elif a==cnt:
        cnt +=1

if cost==len(A):
    print(-1)
else:
    print(cost)

Submission status: Accepted

Solution code:
from sys import stdin 
n = int(stdin.readline().rstrip())
s = [int(x) for x in stdin.readline().rstrip().split()]
t = 1
answer = 0
for i in range(n):
    if s[i] == t:
        t += 1
    else:
        answer += 1
if answer == n:
    print(-1)
else:
    print(answer)

Submission status: Accepted

Solution code:
n = int(input())
a_list = [int(i) for i in input().split()]
key = 1
count = 0

for a in a_list:
  if a == key:
    key += 1
  else:
    count += 1

print(count if key > 1 else -1)

Submission status: Accepted

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


def solve(N: int, a: "List[int]"):
    nok=0
    for i in range(N):
        if a[i]==nok+1:
            nok+=1
#        print("#",i,nok)
    print(-1 if nok==0 else N-nok)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
num = 1

for a in bricks:
    if a == num:
        num += 1
    else:
        ans += 1

if ans == N:
    ans = -1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

ans = 0
now_number = 1

for i in range(N):
  if a_list[i]!= now_number:
    ans += 1
  else:
    now_number += 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()] 

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

x = len(a) - len(ans)
if x == len(a):
    print(-1)
else:
    print(x)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

l = 0

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


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

Submission status: Accepted

Solution code:
import sys 

readline = sys.stdin.buffer.readline

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

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

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


main()

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)
    exit()
ans = n-cnt
print(ans)

Submission status: Accepted

Solution code:
# print('input >>')
N = int(input())
a = list(map(int,(input().split())))

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

# print('-----output-----')
if breaks == N:
    print(-1)
else:
    print(breaks)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
a = [0]+list(map(int, input().split( )))
tmp = 0
cnt =0
if 1 not in a:
    print(-1)
    exit()
for i in range(n+1):
    while tmp <= n and a[tmp]!=i:##<=
        tmp += 1
        cnt += 1
        #print(i,tmp,cnt)
    tmp += 1
    if tmp > n:##>
        break


print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

l=1
k=0
while k<=n-1:
    for i in range(k,n):
        if a[i]==l:
            l+=1
            k=i+1
            break
    else:
        k=n
if l==1:
    print(-1)
else:
    print(n-l+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(n-(now-1))
else:
	print(-1)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from sys import stdin

if __name__ == '__main__':
    N = int(stdin.readline().strip())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    
    current_num = 1
    broken_num = 0
    for i in range(N):
        if a[i] != current_num:
            broken_num += 1
        else:
            current_num += 1
    if current_num > 1:
        print(broken_num)
    else:
        print(-1)

Submission status: Accepted

Solution code:
def d(caps):
    start = count = 0
    num = 1
    for i in range(len(caps)):
        if caps[i] != num:
            count += 1
        else:
            num += 1
    
    if num == 1:
        print(-1)
    else:
        print(count)

input()
s = [int(i) for i in input().rstrip().split(' ')]

d(s)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int, input().split()))
cur = 1
broke = 0
for a in A:
  if cur == a:
    cur += 1
  else:
    broke += 1

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

Submission status: Accepted

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

target = 1 
bk = 0 
for i in a:
        if i == target:
                target += 1
                continue
        else:
                bk += 1
if target == 1:
        print(-1)
else:
        print(bk)

Submission status: Accepted

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

count = 1
break_num = 0

for item in items:
    if item == count:
        count += 1
    else:
        break_num += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import sys

N = int(input())
A = [int(v) for v in sys.stdin.readline().split()]

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

Submission status: Accepted

Solution code:
# coding: utf-8
n = int(input())
A = map(int, input().split())

l = []
i = 1
for a in A:
    if a == i:
        l.append(a)
        i += 1
if len(l) == 0:
    print(-1)
else:
    print(n - len(l))

Submission status: Accepted

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

r = -1
x = 1

for i in range(n):
    if l[i] == x:
        x += 1
if x > 1:
    r = n - x + 1
print(r)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

k = 0
for ai in an:
  if ai == k+1:
    k += 1
if k == 0:
  print(-1)
else:
  print(n-k)

Submission status: Accepted

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

Submission status: Accepted

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

p = 1
c = 0
for a in A:
    if a == p:
        p += 1
    else:
        c += 1

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

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if ans != 0 and tmp ==1:
  print(-1)
else:
  print(ans)

Submission status: Accepted

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

if 1 not in a:
    print(-1)
else:
    now = a.index(1)
    if now == N-1:
        print(N-1)
    else:
        ans = now
        search = 2
        now += 1
        while now <= N-1:
            if a[now] == search:
                search += 1
            else:
                ans += 1
            now += 1
        print(ans)

Submission status: Accepted

Solution code:
from collections import deque

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

blk = 1
cnt = 0

for i in range(N):
    a = A.popleft()

    if a == blk:
        blk += 1
    else:
        cnt += 1

if blk == 1:
    cnt = '-1'

print(cnt)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = 0
j = 1
for a in A:
  if a==j:
    j+=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()))

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

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

Submission status: Accepted

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



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

if number==1:
  print(-1)
else:
  print(break_count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import deque
N = int(input())
a = list(map(int, input().split()))
d = deque(a)

cnt = 0
tmp = 1
i = 0
for _ in range(N):
  D = d.popleft()
  if D == tmp:
    tmp += 1
    i = 1
  else:
    cnt += 1
    
if i != 1:
  print(-1)
else:
  print(cnt)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

o=0
c=1

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

count = 0

for i in a:
    count += int((count+1) == i)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num = int(input())
num_list = [int(s) for s in input().split()]
count = 1
hantei = False
for i in range(0,num):
    if num_list[i] == count:
        count+=1
        hantei = True
if hantei == False:
    print("-1")
else:
    print(num-count+1)

Submission status: Accepted

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

ans = 1
for i, a in enumerate(A):
    if a == ans:
        ans += 1
ans -= 1
if ans == 0:
    print(-1)
else:
    print(len(A) - ans)

Submission status: Accepted

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

target = 1
ans = 0
for a in al:
    if(a == target):
        target += 1
    else:
        ans += 1

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

print(ans)

Submission status: Accepted

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

cnt=0
now=1

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

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

Submission status: Accepted

Solution code:
n = int(input())
test = 1
arr = [int(i) for i in input().split()]
for i in range(n):
    if arr[i] == test:
        # print(i)
        test += 1
if n == 1 and test == 1:
    print(0)
elif test == 1:
    print(-1)
else:
    print(n - test + 1)

Submission status: Accepted

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

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

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