import sys

from fractions import gcd



stdin = sys.stdin



ri = lambda: int(rs())

rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers

rs = lambda: stdin.readline().rstrip()  # ignores trailing space



N = ri()

A = rl()

answer = 0

cur = 1

for i in range(N):

    if A[i] == cur:

        answer += 1

        cur += 1

print((N - answer if answer > 0 else -1))

import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N = ir()

A = lr()

cur = 0

for a in A:

    if a == cur + 1:

        cur += 1



print((N-cur if cur > 0 else -1))

# 54
import sys
from fractions import gcd

stdin = sys.stdin
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space
N = ri()
A = rl()
answer = 0
cur = 1
for i in range(N):
    if A[i] == cur:
        answer += 1
        cur += 1
print((N - answer if answer > 0 else -1))

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N = ir()
A = lr()
cur = 0
for a in A:
    if a == cur + 1:
        cur += 1
print((N - cur if cur > 0 else -1))
# 54

-from fractions import gcd -stdin = sys.stdin -ri = lambda: int(rs()) -rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers -rs = lambda: stdin.readline().rstrip()  # ignores trailing space -N = ri() -A = rl() -answer = 0 -cur = 1 -for i in range(N): -    if A[i] == cur: -        answer += 1 +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) +N = ir() +A = lr() +cur = 0 +for a in A: +    if a == cur + 1: -print((N - answer if answer > 0 else -1)) +print((N - cur if cur > 0 else -1)) +# 54