from collections import deque

n = int(eval(input()))

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



cnt = 0

flag_empty = False

flag_end = False

if not 1 in A:

  cnt = -1

else:

  for i in range(1, n+1):

    if not i in A:

      cnt += len(A)

      break

    while 1:

      a = A.popleft()

      if len(A) == 0: 

        flag_empty = True

        break

      if a != i:

        cnt += 1

      else:

        break

    if flag_empty:

      break

   

print(cnt)
from collections import deque

n = int(eval(input()))

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



next_ = 1

cnt = 0

for i in A:

  if i == next_:

    next_ += 1

  else:

    cnt += 1

if cnt == n:

  cnt = -1

print(cnt)
from collections import deque

n = int(eval(input()))
A = deque(list(map(int, input().split())))
cnt = 0
flag_empty = False
flag_end = False
if not 1 in A:
    cnt = -1
else:
    for i in range(1, n + 1):
        if not i in A:
            cnt += len(A)
            break
        while 1:
            a = A.popleft()
            if len(A) == 0:
                flag_empty = True
                break
            if a != i:
                cnt += 1
            else:
                break
        if flag_empty:
            break
print(cnt)

from collections import deque

n = int(eval(input()))
A = deque(list(map(int, input().split())))
next_ = 1
cnt = 0
for i in A:
    if i == next_:
        next_ += 1
    else:
        cnt += 1
if cnt == n:
    cnt = -1
print(cnt)

+next_ = 1 -flag_empty = False -flag_end = False -if not 1 in A: +for i in A: +    if i == next_: +        next_ += 1 +    else: +        cnt += 1 +if cnt == n: -else: -    for i in range(1, n + 1): -        if not i in A: -            cnt += len(A) -            break -        while 1: -            a = A.popleft() -            if len(A) == 0: -                flag_empty = True -                break -            if a != i: -                cnt += 1 -            else: -                break -        if flag_empty: -            break