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: Time Limit Exceeded

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

#単入力
n=int(input())

#リスト入力
l = [int(i) for i in input().split()]

count = 0
for i in range(1,200000):
    #if i in l:
    #    count+=1
    #    position=l.index(i)
    #    del l[:position]
    #else:
    #    break
    try:
        position=l.index(i)
    except ValueError:
        break
    del l[:position]
    count+=1
if count == 0:
    print(-1)
else:
    print(n-count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
pre_len = len(a) # 最初の長さ
ans = list()
for i in range(1,N+1):
	try:
		del a[:a.index(i)]
		ans.append(a[0])
	except ValueError :
		break

if len(ans) == 0:
	print(-1)
else:
	print(pre_len-len(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
#print(A)
n = 1#番号
c = 0#砕き
i = 0

while len(A)>i:
    if A[i] == n:
        i += 1
        n += 1
    else:
        A.pop(i)
        c += 1
    #print(A,"i=",i,"c=",c,"n=",n)

if len(A) == 0:
    print(-1)
else:
    print(c)

Submission status: Time Limit Exceeded

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

i = 0
while i < len(a):
    if a[i] == i+1:
        i = i + 1
    else:
        a = a[0:i] + a[i+1:]
        c = c + 1

if i == 0:
    c = -1
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
alist = list(map(int, input().split()))
alen = len(alist)

n = 0
i = 1
i2 = 0
all = 0
while True:
    if alist[i2] != i:
        n += 1
        alist.pop(i2)
    else:
        i += 1
        i2 += 1
    all += 1
    if all >= alen: break

if len(alist) == 0:
    print(-1)
else:
    print(n)

Submission status: Time Limit Exceeded

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

A = [a for i, a in enumerate(A) if a <= i+1]
A = [a for i, a in enumerate(A) if a <= i+1]
k = 0

while k < len(A):
    if A[k] != k+1:
        A.pop(k)
    else:
        k += 1

if len(A) == 0:
    print(-1)
else:
    print(N - len(A))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = list(map(int,input().split()))
flag = 0
count = 0

if 1 in a:
    pass
else:
    print(-1)
    exit()
    
for i in range(1,n+1):
    if i in a:
        indx = a.index(i)
        count += indx
        a = a[indx+1:]
        # print(count)
        # print(a)
    else:
        count += len(a)
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [int(e) for e in input().split()]
jun = 1
stopper = 0
kosu=0
for i in range(N):
    for j in range(N):
        if a[stopper + i] == jun:
            kosu += 1
            stopper = j
            jun+=1
            break
if kosu!=0:
    print(N - kosu)
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int,input().split()))
maxA = max(A)
prv_ii = 0
cnt = 0
for i in range(1,maxA+1):
  try:
    ii = A[prv_ii:].index(i)
    cnt += 1
    prv_ii = ii + prv_ii + 1 
  except:
    break
print(N-cnt if cnt!=0 else -1)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

if numbers == [] or 1 not in numbers:
    print(-1)
    sys.exit(0)

index = 0
value = 1
breaks = 0
while True:
    while numbers[index] != value:
        if index >= len(numbers):
            print(-1)
            sys.exit(0)
        numbers.pop(index)
        breaks += 1
    index += 1
    value += 1
    if index >= len(numbers):
        print(breaks)
        sys.exit(0)

Submission status: Time Limit Exceeded

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

start = 0
cnt = 0
for i in range(1, N+1):
  try:
    start = a[start:].index(i)
  except:
    break
  else:
    cnt += 1

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

Submission status: Time Limit Exceeded

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


def main():
    sc = Scan()
    n = sc.intarr()[0]
    A = sc.intarr()
    origin_len = len(A)

    count = 1
    while True:
        try:
            index = A.index(count)
            A = A[index:]
            count += 1
        except ValueError:
            if count == 1:
                print("-1")
                return
            else:
                print(origin_len + 1 - count)
                return
            break

    print("fin")
    print(origin_len - len(A))


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(x, y):
    return (x * y) // gcd(x, y)


def natural_num(n):
    for j in range(2, int(math.sqrt(n))+1):
        if n % j == 0:
            return 0
    return 1


main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
sorted_A = sorted(A)
ans = 0
l = []
if 1 not in A:
    print(-1)
    exit()

i = 0
while True:
    if A == sorted_A:
        print(N - len(set(A)))
        exit()
        break
    if A[i] > sorted_A[i]:
        tmp = A[i]
        A.remove(tmp)
        sorted_A.remove(tmp)
        continue
    i += 1

Submission status: Time Limit Exceeded

Solution code:
def main():
    # input = sys.stdin.readline
    N = int(input())
    raw_list = list(map(int, input().split()))
    new_list = raw_list

    count = 0
    for i in range(1, N+1):
        if i in new_list:
            idx = new_list.index(i)
            new_list = new_list[idx+1:]
            count += idx
        else:
            count += len(new_list)
            break

    if 1 not in raw_list:
        count = -1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

#単入力
n=int(input())

#リスト入力
l = [int(i) for i in input().split()]

count = 0
for i in range(1,200000):
    if i in l:
        count+=1
        position=l.index(i)
        del l[:position]
    else:
        break
if count == 0:
    print(-1)
else:
    print(n-count)

Submission status: Time Limit Exceeded

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

pos = 1
ans = 0
leng = len(alist)
while(len(alist) > 0 and pos <= len(alist)):
    if (pos != alist[pos-1]):
        del(alist[pos-1])        
        ans += 1
        continue
    else:
        pos += 1

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

Submission status: Time Limit Exceeded

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

la = len(a)
tmp = 1
cnt = 0
for num in range(n):
  for i,ai in enumerate(a):
    if ai == tmp:
      a = a[i:]
      tmp += 1
      cnt += 1
      break
if cnt == 0:
  print(-1)
else:
  print(la - cnt)

Submission status: Time Limit Exceeded

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

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

# 1から順番に並べられたらOK
a = 1
c = 0
for i in range(N):
    if A[0] == a:
        # 確定した扱い
        a += 1
    else:
        # 取り除いた扱い
        c += 1
    A.pop(0)

print(c if a > 1 else -1)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = list(map(int,input().split()))
A = [i+1 for i in range(N)]

k = 0
for i in range(N):
  if a[i] == min(A):
    A.remove(a[i])
    k += 1
if k != 0:
  print(N - k)
else:
  print(-1)

Submission status: Time Limit Exceeded

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

if 1 in a:
    while i<len(a):
        if a[i]!=i+1:
            del a[i]
            ans+=1
        else:
            i+=1
else:
    ans=-1
print(ans)

Submission status: Time Limit Exceeded

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

if 1 in a:
    while i<len(a):
        if a[i]!=i+1:
            del a[i]
            ans+=1
        else:
            i+=1
else:
    ans=-1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
idx = 0
cnt = 0
for n in range(N):
    if A[idx] == idx+1:
        idx += 1
    else:
        A.pop(idx)
        cnt += 1

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

Submission status: Time Limit Exceeded

Solution code:
import sys


def main():
    # input = sys.stdin.readline
    N = int(input())
    raw_list = list(map(int, input().split()))
    new_list = raw_list.copy()

    count = 0
    for i in range(1, N+1):
        if i in new_list:
            idx = new_list.index(i)
            new_list = new_list[idx+1:].copy()
            count += idx
        else:
            count += len(new_list)
            break

    if 1 not in raw_list:
        count = -1

    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

k = 0
idx = -1
while True:
  if k + 1 in a[(idx + 1):]:
    idx += a[(idx + 1):].index(k + 1) + 1
    k += 1
  else:
    break

print(n - k if k > 0 else -1)

Submission status: Time Limit Exceeded

Solution code:
import sys

n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
cnt=0
while True:
    for i, a in enumerate(A):
        if A[i] != i+1:
            A.pop(i)
            cnt+=1
            break
    else:
        break

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

Submission status: Time Limit Exceeded

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

l=a
for i in a:
  if i==flag:
    flag+=1
  else:
    l=a[1:]
    count+=1
if count==n:
  print(-1)
else:
  print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
first = n
k = [int(x) for x in input().split()]
i=0
while(i<n):
    #print("i="+str(i)+"k[]="+str(k[i]))
    if(k[i]!=i+1): 
        k.pop(i)
        n-=1
    else: i+=1
if(n==0): print("-1")
else: print(first-n)

Submission status: Time Limit Exceeded

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if ans == len(l):
    print (-1)
else:
    print (ans)

Submission status: Accepted

Solution code:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main2():
    numbers=[]
    N = int(input())
    numbers=list(map(int,input().split()))
    n=1

#条件が1<=n<=200kのため1から順に数えてlist内を調査した場合の最大値+1をnに記入
    for x in numbers:
        if x ==n:
            n+=1

#条件から+1まで数えてしまうため、nを+1して調整
    answer = N - n +1

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

def main():
    numbers=[]
    n = int(input())
    numbers=list(map(int,input().split()))
    buffer=[0]
    for i in range(1,n+1):
        search_range=numbers[i-1:]
        out_range=len(numbers[:i-1])
        if i not in search_range and len(buffer)==1:
            print(-1)
            exit()
        elif i not in search_range or i==n:
            break
        else:
            index=search_range.index(i)
            buffer.append(index-sum(buffer))
    print(sum(buffer))

if __name__=="__main__":
    main2()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

count=0
z=True
j=0

if  1 not in a:
    print(-1)
else:
    for k in range(j,n):
        if a[k]==count+1:
            j=k
            count=count+1

    print(n-count)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(-1 if A.count(1) == 0 else cnt)

Submission status: Accepted

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

if n == 1 and al[0] == 1:
    print(0)
else:
    i, j, num, ans = 0, 0, 1, 0
    while i < n:
        if al[i] != num:
            i += 1
        else:
            ans += i-j
            j = i+1
            num += 1
            i += 1

    # print(i, j, ans)

    if num != 1 and j != n:
        ans += i-j

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n=int(input())
A=list(map(int,input().split()))
num=1
brk=0
for i in range(n):
  if A[i]==num:
    num+=1
  else:
    brk+=1

if num==1 and brk!=0:
  print(-1)
else:
  print(brk)

Submission status: Accepted

Solution code:
# coding: utf-8

def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = -1
    tmp = 1
    flg = False

    for a in A:
        if a == tmp:
            tmp += 1
            flg = True

    if flg:
        ans = N - tmp + 1

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    a = i_list()

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


if __name__=="__main__":
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def abc148d_brick_break():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = 0
    val = 1
    for item in a:
        if item == val:
            val += 1
        else:
            cnt += 1
    if val == 1:
        print('-1')
    else:
        print(cnt)
abc148d_brick_break()

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
i = 0
j = 0
while i < n:
    if a_l[i] == j+1:
        j += 1
        i += 1
        continue
    ans += 1
    i += 1
if ans > n-1:
    print('-1')
else:
    print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    cnt = 0
    for a in A:
        if a == cnt + 1:
            cnt += 1

    if cnt == 0:
        return -1
    return N - cnt


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    answer = solve(N, A)
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=len(a)
result=1
i=0
j=0
while True:
    if a[i]==result:
        result+=1
    i+=1
    if i>=b:
        break
if result==1:
    print(-1)
else:
    print(b-result+1)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    lst = LI()
    cnt = 1
    ans = 0

    for brock in lst:
        if brock == cnt:
            cnt += 1
        else:
            ans += 1

    if cnt != 1:
        print(ans)
    else:
        print(-1)
    
main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
k = 0
flg = False
for ai in a:
  if ai == k + 1:
    k += 1
  else:
    flg = True
if k == 0 and flg:
  print(-1)
else:
  print(n - k)

Submission status: Accepted

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

ans=0
j=1
for i in s:
    if i!=j :
        ans+=1
    else:
        j+=1
print(ans) if ans<n else print(-1)

Submission status: Accepted

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

flag=0
i=0
now=1
cnt=0
ans=0

if 1 not in A:
	print(-1)
	
else:
	while flag==0:
		if A[-(i+1)]!=now:
			A.pop(-(i+1))
			cnt+=1
			ans+=1
		else:
			i+=1
			cnt+=1
			now+=1
		
		if cnt==N:
			flag=1
	
	print(ans)

Submission status: Accepted

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

for a in A:
  if a==n:
    n+=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()))
n = 1
ans = 0
for i in a:
    if i != n:
        ans += 1
    else:
        n +=1
if n == 1:
    print("-1")
else:
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 148
# D - Brick Break

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

targetnum=1
breaknum=0

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

Submission status: Accepted

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

next_number = 1
cnt = 0
for a in A:
  if a == next_number:
    next_number += 1
  else:
    cnt += 1
if cnt == len(A):
  print('-1')
else:
  print(cnt)

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:
# ABC 148 D

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

K=1
dest=0
for a in A:
    if a==K:
        K+=1
    else:
        dest+=1
print(dest if K>1 else -1)

Submission status: Accepted

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

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

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

print(N-cnt)

Submission status: Accepted

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

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

l = []
min_num = 0
for i in a:
    if i == min_num + 1:
        l.append(i)
        min_num += 1

print(N-len(l))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt = 0
idx = 1
for i, a in enumerate(A):
    if idx == a:
        idx += 1
    else:
        cnt += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 1
cnt = 0

if ans not in a:
  print(-1)
  exit()
for i in a:
  if i == ans:
    ans += 1
    continue
  cnt += 1
  
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
a = map(int, input().split())
counter = 0
for ai in a:
    if counter + 1 == ai:
        counter += 1
print(N - counter if counter != 0 else '-1')

Submission status: Accepted

Solution code:
import os
import heapq
import sys,threading
import math
import bisect
import operator
from collections import defaultdict
sys.setrecursionlimit(10**5)
from io import BytesIO, IOBase
def gcd(a,b):
    if b==0:

        return a
    else:
        return gcd(b,a%b)
def power(x, p,m):
    res = 1
    while p:
        if p & 1:
            res = (res * x) % m
        x = (x * x) % m
        p >>= 1
    return res
def inar():
    return [int(k) for k in input().split()]

def lcm(num1,num2):
    return (num1*num2)//gcd(num1,num2)

def main():
    n=int(input())
    arr=inar()
    count=1
    for i in range(n):
        if arr[i]==count:
            count+=1
    # print(count
    if count==1:
        print(-1)
    else:
        print(n-count+1)






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")


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

if __name__ == "__main__":
    main()
    #threadin.Thread(target=main).start()

Submission status: Accepted

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

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    A=LI()
    cnt=0
    now=1
    
    for i in range(N):
        if A[i]==now:
            now+=1
        else:
            cnt+=1
            
    if cnt==N:
        cnt=-1
    print(cnt)
        

main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
import statistics
a=int(input())
#b=int(input())
# c=[]
# for i in b:
#     c.append(i)
# e1,e2 = map(int,input().split())
f = list(map(int,input().split()))
#j = [input() for _ in range(3)]
# h = []
# for i in range(e1):
#     h.append(list(map(int,input().split())))
ans=0
count=0
for i in range(a):
    if ans+1 == f[i]:
        ans=f[i]
        count+=1
if count>0:   
    print(len(f)-count)
else:
    print(-1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 01:08:27 2020

@author: liang
"""

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

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

Submission status: Accepted

Solution code:
import sys

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


if A.count(1) == 0:
  print(-1)
  sys.exit()
else:
  
  cnt = 0
  for a in range(len(A)):
    if A[a] == cnt+1:
      cnt += 1
  print(len(A)-cnt)

Submission status: Accepted

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

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

Submission status: Accepted

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

cnt = 0

for i in range(len(a)):
    if i+1-cnt != a[i]:
        cnt += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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