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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
a_list=[int(ai)-1 for ai in input().split(' ')]

num_total_break=0
index=0

def run(a_list, index):
	num_break=0
	ret=[]
	found=False
	for ai in a_list:
		if found==False and ai!=index:
			num_break+=1
		elif found==False and ai==index:
			found=True
		elif found==True and ai!=index:
			ret.append(ai)
		else:
			num_break+=1
	return ret, num_break, found

while True:
	if len(a_list)==0:
		print(num_total_break)
		break
	else:
		a_list, new_break, found = run(a_list, index)
		index+=1
		num_total_break+=new_break
		if found==False:
			print(-1)
			break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

k=1
cnt=0
for i in range(n):
  if A[i]!=k:
    cnt+=1
  else:
    k+=1
if cnt==n:
  print(-1)
else:
  print(-1)

Submission status: Wrong Answer

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

for i in range(n):
  num = i + 1
  for s in range(l,n):
    print(l)
    print(s)
    if num == a[s]:
      l = s + 1
      print('break')
      if count == -1:
        count = 0
      break
    else:
      print('count')
      count = count + 1

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(n):
  num = i + 1
  if 1 not in a:
    break
  for s in a:
    if num == s:
      if count == -1:
        count = 0
      else:
        count = count + 1
      break

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(n-x)

Submission status: Wrong Answer

Solution code:
n, *list = map( int , open(0).read().split())

def index_def( i, list,  default ):
  if i in list:
    return list.index( i )
  return default

block_destroy_counter = 0
for i in range(1 , n + 1 ):
  a = index_def(i, list, -1 )
  list = list[a+1:]
  if a == -1:
    break
  block_destroy_counter += a 

print( block_destroy_counter )

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = input().split()
for i in range(N):
  a[i] = int(a[i])
index = 1
count = 0
for i in range(N):
  if a[i] == index:
  	index += 1
  else:
    count += 1
print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int,input().split())) 
j=2
if 1 in L:
  while j<=int(max(L)):
    i=0
    while True:
      if L[i]==j:
        break
      else:
        L.remove(L[i])
    else:
      j+=1
  else:
    print(N-len(L))
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
quantity = int(input())
block = list(map(int,input().rstrip().split(" ")))

num = 1
for i in block:
    if i == num:
        num += 1

if num == 1:
    print(0)
else:
    print(quantity - num + 1)

Submission status: Wrong Answer

Solution code:
quantity = int(input())
block = list(map(int,input().rstrip().split(" ")))

print(block)

num = 1
for i in block:
    if i == num:
        num += 1

if num == 1:
    print(0)
else:
    print(quantity - num + 1)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
print(a)
if a.count(1)==0:
    print(-1)
else:
    ans=[]
    for i in range(N):
        if a[i]==len(ans)+1:
            ans.append(a[i])
    #print(N)
    #print(len(ans))
    print(N-len(ans))

Submission status: Wrong Answer

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

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

breakpoint = 0
stoppoint = 0

for i in range(n):
    for j in range(stoppoint,n):
        if li[j] != i+1:
            breakpoint += 1
        else:
            stoppoint = j+1
            break
    if breakpoint == n:
        breakpoint = -1
        break
    elif stoppoint == n:
    	break

print(breakpoint)

Submission status: Wrong Answer

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

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

breakpoint = 0
stoppoint = 0

for i in range(n):
    for j in range(stoppoint,n):
        if li[j] != i+1:
            breakpoint += 1
        else:
            stoppoint = j+1
            break
    if breakpoint == n:
        breakpoint = -1
        break

print(breakpoint)

Submission status: Wrong Answer

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

breakpoint = 0
stoppoint = 0

for i in range(n):
    for j in range(stoppoint,n):
        if li[j] != i+1:
            breakpoint += 1
        else:
            stoppoint = j+1
            break
    if breakpoint == n:
        breakpoint = -1
        break

print(breakpoint)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = input()
nums = list(map(int,input().split()))
print(nums)
index , pre= 0,0
max_num = 1
ans = 0
if not max_num in nums:
  print(-1)
  exit()
while 1:
  for i,n in enumerate(nums):
    if i < index:
      continue
    if n == max_num:
      index=i
      max_num+=1
      ans+=1
  if index == pre:
    if ans == 0:
      print(ans)
    else:
      print(len(nums)-ans)
    break
  pre=index

Submission status: Wrong Answer

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

def list_sort(l):
    for i, x in enumerate(l):
        if (i + 1) == x:
            pass
        else:
            return False
            break
    else:
        return True
        
def c(index, l):
    if list(filter(lambda x: x > l[index], l[index:])):
        return False
    else:
        return True
    

l = []
pre_num = a[0]
num = 1
del_num = 0

n=0

index = 0
for x in range(1, max(a)+1):
    try:
        i = a[index:].index(x)
    except ValueError:
        print(-1)
        sys.exit()
        
    n += 1
    #print(n)
    #print(index)
    index = i + index
    if c(index, a):
        print(len(a)-n)
        sys.exit()

Submission status: Wrong Answer

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

def list_sort(l):
    for i, x in enumerate(l):
        if (i + 1) == x:
            pass
        else:
            return False
            break
    else:
        return True

l = []
pre_num = a[0]
num = 1
del_num = 0

while not list_sort(a):
    try:
        num_index = a.index(num)
    except ValueError:
        print(-1)
        sys.exit()
        
    if num_index <= 0:
        l.append(a.pop(num_index))
        pass
    else:
        del_num += len(a[:num_index])
        del a[:num_index]
        l.append(a.pop(a.index(num)))
        
    num += 1
    
print(del_num)

Submission status: Wrong Answer

Solution code:
n = int(input())
base = 10
ans = 0
 
if n%2 == 1:
  print(0)
else:
  for i in range(1,10000):
    ans += n//base
    base *= 5   
  print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
base = 10
ans = 0

if n%2 != 0:
  print(0)
else:
  for i in range(1,10000):
    ans += n//base
    base *= 5   
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def func1(lst, value):
    return [i for i, x in enumerate(lst) if x == value]

n = int(input())
box = []
box.append(list(map(int, input().split())))
box1 = box[0]  
tibi = min(box1)
ans = 0

#判定
if tibi!=1:
  print(-1)
else:
  iti = func1(box1, 1)
  iti_left = min(iti)
  ans += (iti_left + 1)
  del box1[:iti_left]
  num = 0
  for i in range(len(box1)):
    if box1[i]==(num+1):
      num += 1
      continue
    else:
      ans += 1
      
print(ans)

Submission status: Wrong Answer

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

while (1):
  if i in a[cnt:]:
      cnt += a[cnt:].count(i)
      i += 1
  else:
    break
if i==1:
  print(-1)
else:
  print(n-i+1)

Submission status: Wrong Answer

Solution code:
n = int(input());
s = list(map(int,input().split()))
ans = 0
for i in range(n):
  if (s == sorted(s,reverse=True)) or (s == sorted(s,reverse=False)):
    break
  else:
    ans +=1
    s.pop(0)
print(-1 if ans==0 else ans)

Submission status: Wrong Answer

Solution code:
n = int(input());
s = list(map(int,input().split()))
ans = 0
for i in range(n):
  if (s == sorted(s,reverse=True)) or (s == sorted(s,reverse=False)):
    break
  else:
    ans +=1
    s.pop(0)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
if len(a)>n:
  	print(-1)
if len(set(a)) == 1:
    if list(set(a))[0] != 1:
        print(-1)
        exit()
    else:
        print(0)
        exit()

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
    if list(set(a))[0] != 1:
        print(-1)
        exit()
    else:
        print(0)
        exit()

x = 1
count = 0
for i in a:
    if i == x:
        x+=1
    else:
        count+=1
if count == n or len(a)>n:
    print(-1)
else:
    print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
    if list(set(a))[0] != 1:
        print(-1)
        exit()
    else:
        print(0)
        exit()

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

Submission status: Wrong Answer

Solution code:
N = int(input())
s =input().split()

cnt = 0
flag = -1

for i in range(0,N):

    if i == 0:
        continue
    elif i == int(s[i]):
        continue
    else:
       #s.pop(i-1)
       cnt = cnt + 1
       flag = 1

if flag == 1:
    print(cnt)
else:
    print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
s =input().split()

cnt = 0


for i in range(1,N-1):

    if i == 0:
        continue
    elif i == int(s[i]):
        continue
    else:
       #s.pop(i-1)
       cnt = cnt + 1

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
if n == 1:
	if a[0] == 1:
		print (0)
		exit()
	else:
		print (-1)
		exit()
b = set(a)
if len(b) == 1:
	print (-1)
	exit()

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
if n == 1:
	if a[0] == 1:
		print (0)
		exit()
	else:
		print (-1)
		exit()
b = set(a)
if len(b) == 1:
	print (-1)
	exit()

x = 1
cnt = 0
for i in a:
	if i == x:
		x += 1
	else:
		cnt += 1
print(cnt)

Submission status: Wrong Answer

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

pos, v = 1, 0

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

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

Submission status: Wrong Answer

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

count = 0

i = 1
k = 1
index = 0


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

if index != 0 or (n == 1 and a[0] == 1):
    print(n-count)
else:
    print("-1")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a =	list(map(int, input().split()))
cnt = 0
for i in a :
    if i == cnt + 1 :
        cnt = cnt + 1
if cnt == 0 :
    cnt = -1
print(n - cnt)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
a =	list(map(int, input().split()))
cnt = 0
for i in a :
    if i == cnt + 1 :
        cnt = cnt + 1
print(n - cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(n) for n in input().split()]
idx = 0
c = 0
if 1 not in a:
    print(-1)
else:
    try:
        for i in range(1, N+1):
            idx += a[idx:].index(i)
            c += 1
    except ValueError:
        pass
print(N-c)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(n) for n in input().split()]
idx = 0
c = 0
if 1 not in a:
    print(-1)
else:
    for i in range(1, N+1):
        try:
            idx += a[idx:].index(i)
            c += 1
        except ValueError:
            break
print(N-c)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(n) for n in input().split()]
idx = 0
c = 0
if 1 not in a:
    print(-1)
else:
    for i in range(1, N+1):
        try:
            print(i, idx)
            idx += a[idx:].index(i)
            c += 1
        except ValueError:
            break
print(N-c)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(n) for n in input().split()]
idx = 0
c = 0
if 1 not in a:
    print(-1)
else:
    for i in range(1, N+1):
        try:
            idx = a[idx:].index(i)
            c += 1
        except ValueError:
            break
print(N-c)

Submission status: Wrong Answer

Solution code:
a=int(input())
l=[int(x) for x in input().rstrip().split()]
flag=0
c=0
j=0
flag=0
for i in range(1,a+1):

    if l.count(i)!=0:
        if 1<i:
            flag=1
        idx=l.index(i)
        if i-1 != idx:
            c+=len(l[i-1:idx])
            del l[i-1:idx]
        
        elif i-1==idx:

            flag=1
            continue
    
    else:
        break
if flag==0:
    print(-1)
else:
    print(c)

Submission status: Wrong Answer

Solution code:


from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n = ii()
    a = li()

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

    
main()

Submission status: Wrong Answer

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

if a==(list(i+1 for i in range(N))):
       print(0)
       exit()

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

Submission status: Wrong Answer

Solution code:
count = 1
ans = 0
point = 0
n = int(input())
t = list(map(int,input().split()))
for i,j in enumerate(t):
	if j == count:
		ans += i - point
		point = i + 1
		count += 1
if not point == n:
	ans += n - 1 - point
if count == 1:
	try:
		t.index(1)
	except:
		ans = -1
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
count = 1
ans = 0
point = 0
n = int(input())
t = list(map(int,input().split()))
for i,j in enumerate(t):
	if j == count:
		ans += i - point
		point = i + 1
		count += 1
if point <= i:
	ans += i - point
if count == 1:
	try:
		t.index(1)
	except:
		ans = -1
print(ans)

Submission status: Wrong Answer

Solution code:
count = 1
ans = 0
point = 0
n = int(input())
t = list(map(int,input().split()))
for i,j in enumerate(t):
	if j == count:
		ans += i - point
		point = i + 1
		count += 1
if count == 1:
	try:
		t.index(1)
	except:
		ans = -1
print(ans)

Submission status: Wrong Answer

Solution code:
count = 1
ans = 0
point = 0
n = int(input())
t = list(map(int,input().split()))
for i,j in enumerate(t):
	if j == count:
		ans += i - point
		point = i + 1
		count += 1
if ans == 0:
	try:
		t.index(1)
	except:
		ans = -1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
a = map(int,raw_input().split())
con = 0
i = 0
while i < 200000:
  if len(a)==0:
    con = -1
    print con
    break
  elif len(a)==con:
    print N-con
    break
  if a[con] == con+1:
    con = con + 1
  else:
    a.pop(con)
  i= i+1

Submission status: Wrong Answer

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

while True:
  if len(a)==0:
    con = -1
    break
  elif len(a)==con:
    break
  if a[con] == con+1:
    con = con + 1
    continue
  else:
    a.pop(con)

print N-con

Submission status: Wrong Answer

Solution code:
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    a = inputIntList()
    ans = 0
    look = 1
    current = 0
    while current < len(a):
        for i, j in enumerate(a[current:]):
            if j == look:
                # print(i)
                ans += i
                current += i+1
                break
        look += 1
        # print(look, current, ans)
    return ans


if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

Solution code:
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    a = inputIntList()
    ans = 0
    look = 1
    current = 0
    while current < len(a) - 1:
        for i, j in enumerate(a[current:]):
            if j == look:
                print(i)
                ans += i
                current += i+1
                break
        look += 1
        # print(look, current, ans)
    return ans


if __name__ == "__main__":
    print(main())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
now = 1 
for i in range(N):
	if now == A[i]:
		now += 1 
print("{}".format(N - now + 1))

Submission status: Wrong Answer

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

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

from fractions import gcd

n = int(input())
a = [int(i) for i in readline().split()]


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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
List_Bricks = [int(i) for i in input().split()]
#print(List_Bricks)
Search = 1
Kudaku = 0
i = 0
Boole = False
Count = 0
L = len(List_Bricks)-1
while List_Bricks != [j for j in range(1,len(List_Bricks)+1)]:
    try:
        X = List_Bricks.index(Search)
        del List_Bricks[i:X]
        #print("I found it",X)
    except ValueError:
        if Count == 0:
            print(-1)
            sys.exit(0)
        else:
            print(Kudaku)
            sys.exit(0)
    else:
        i+=1
        Kudaku += (X-i+1)
        Search += 1
        Count += 1
        #print("Search is=",Search)
        #print(List_Bricks)
        #print("Kudaku is=",Kudaku)
print(Kudaku)

Submission status: Wrong Answer

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

cnt = 0
track = 1

for i in range(n) :
	if cnt!=1 :
		if arr[i]!=track :
			arr[i] = -1
		else :
			track+=1
			cnt = 1
	else :
		if arr[i] !=track and arr[i]!=track-1 :
			arr[i] = -1
		else:
			track+=1


res = set(arr)

if -1 in res :
	res.remove(-1)

ans = n - len(res)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

print(n-cnt+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
# a,b = map(int,input().split())
a = input().replace(' ','') #split()))
ans = 0

for i in range(n):
    tmp = a.find(str(i+1))
    a=a[tmp+1:]
    # print(tmp)
    if tmp == -1:
        break
    else:
        ans=i+1

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
i8 = np.int64


def solve(a):
    x = 1
    res = 0
    for i in range(a.shape[0]):
        if a[i] == x:
            x += 1
        else:
            res += 1
    return res


def main():
    stdin = open('/dev/stdin', 'rb')
    pin = np.fromstring(stdin.read(), i8, sep=' ')
    a = pin[1:]
    ans = solve(a)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
cont = 0
for i in a:
    if i == 1:
        cont += 1
if cont < 1:
    print(-1)
    exit()
cnt = 0
i = 0
pivot = 0
for i in range(n):
    for j in range(pivot,n):
        if i+1 != a[j]:
            cnt += 1
        elif i+1 == a[j]:
            pivot = j+1
            break
print(cnt)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

next = 1
ans = 0

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

print(ans)

Submission status: Wrong Answer

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

i = 0
x = 1

while i < len(a):
    if a[i] == x:
        del a[x-1:i]
        i = x-1
        x += 1

    i += 1

print(n - len(a) if x > 1 else -1)

Submission status: Wrong Answer

Solution code:
N = int(input())
ori = [int(i) for i in input().split()]
count = ori.count(1)
if count == 0:
    print(-1)

else:
    Break = 0
    for j in range(1,N+1):
        for i in range(Break,N):
            if ori[i] == j:
                Break = i
                #print(Break)
                #print(savepoint)
                #print(j,i)
                sub = j
                break
        if i == N-1:
            break
    print(Break+1-sub)

Submission status: Wrong Answer

Solution code:
N = int(input())
ori = [int(i) for i in input().split()]
count = ori.count(1)
if count == 0:
    print(-1)

else:
    Break = 0
    quit  = 0
    for j in range(1,N+1):
        for i in range(Break,N):
            if ori[i] == j:
                Break = i
                #print(Break)
                #print(savepoint)
                #print(j,i)
                sub = j
                break
        if i == N-1:
            break
    print(Break+1-sub)

Submission status: Wrong Answer

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

ct = 1
ans = 0
if n == 1:
    print(0 if l[0] == 1 else -1)
else:
    for i in range(n):
        if l[i] == ct:
            ans += 1
            ct += 1
        else:
            pass
        
    print(ans if ans > 0 else -1)

Submission status: Wrong Answer

Solution code:
def input():
    import sys
    return sys.stdin.readline().rstrip()
  
def main():
  N = int(input())
  a = list(map(int, input().split()))
  index = 1
  break_ = 0
  #ans = []
  for i in range(N):
    if index != a[i]: #一致しなかったら壊す
      break_ += 1
    else: #一致したら次
      #ans.append(index + 1)
      index += 1
  #print(index)
  #print(break_)
  #print([i + 1 for i in range(N - break_)])
  #print(ans)
  #print(a)
  if index + break_ != N:
    if N == 1 and a[0] == 1:
      print(0)
    else:
      print(-1)
  else:
    print(break_)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
count = 0
start = 0
for i in range(N):
    num = i + 1
    if count == N:
        break
    for j in range(start,N):
        if a[j] == num:
            start = j+1
            break;
        else:
            count += 1
    
if count == N:
    print("-1")
else:
    print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
ori = [int(i) for i in input().split()]
count = ori.count(1)
if count == 0:
    print(-1)
Break = 0
quit  = 0
for j in range(1,N+1):
    for i in range(Break,N):
        if ori[i] == j:
            Break = i
            #print(Break)
            #print(savepoint)
            #print(j,i)
            sub = j
            break
        #else: 
            #quit = 1
            #break
    #if quit == 1:
        #print(quit)
        #break
print(Break+1-sub)

Submission status: Wrong Answer

Solution code:
n = int(input()) - 1
k = 1
for x in map(int, input().split()):
  if x == k:
    k += 1
print(n-(k or n+1))

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
input = input().split()
if input.count('1') == 0:
    print(-1)
    sys.exit()
i = 1
index = 0
while i<=N:
    if input.count(str(i)) == 0:
        break
    j = index
    while j<N:
        if int(input[j]) == i:
            if i==1:
                for k in range(j):
                    input[k] = 0
            else:
                k = index+1
                while k < j:
                    input[k] = 0
                    k += 1
            index = j
            break
        j += 1
    i += 1
print(input.count(0))

Submission status: Wrong Answer

Solution code:
def hantei(n,data):
    tempdata = data[::-1]
    last_num = 1
    if last_num not in tempdata:
        return -1

    while True:
        tempdata = data[:tempdata.index(last_num)+1]
        if last_num + 1 in tempdata:
            last_num += 1
        else:
            break

    return n - last_num

n = int(input())
data = [int(x) for x in input().split()]

print(hantei(n,data))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = []
idx = 0
for n in range(1, N+1):
    try:
        idx += A[idx:].index(n)
    except:
        break

if idx:
    print(len(A[:idx])-(n-2) + len(A[idx+1:]))
else:
    if 1 in A:
        print(len(A)-1)
    else:
        print(-1)

Submission status: Wrong Answer

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

k=1
cnt=0
for i in range(n):
  if A[i]!=k:
    cnt+=1
  else:
    k+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
input = input().split()
if input.count('1') == 0:
    print(-1)
    sys.exit()
i = 1
index = 0
while i<=N:
    if input.count(str(i)) == 0:
        break
    for j in range(N):
        if int(input[j]) == i:
            # print(j)
            if i==1:
                for k in range(j):
                    input[k] = 0
            else:
                k = index+1
                while k < j:
                    input[k] = 0
                    k += 1
            index = j
            break
    i += 1
print(input.count(0))