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))
import sys

readline = sys.stdin.buffer.readline

 

n = int(readline())

num = 1

res = 0

for i in readline().split():

  if num != int(i):

    res += 1

  else:

    num += 1

if res == n:

  print((-1))

else:

  print(res)
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))

import sys

readline = sys.stdin.buffer.readline
n = int(readline())
num = 1
res = 0
for i in readline().split():
    if num != int(i):
        res += 1
    else:
        num += 1
if res == n:
    print((-1))
else:
    print(res)

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