import sys



read = sys.stdin.read

N, *a = list(map(int, read().split()))

a = [0] + a



seq = []

idx = 1

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

    if a[i] == idx:

        seq.append(idx)

        idx += 1



if seq:

    print((N - len(seq)))

else:

    print((-1))
import sys



read = sys.stdin.read

N, *a = list(map(int, read().split()))



cnt = 0

idx = 1

for i in a:

    if i == idx:

        cnt += 1

        idx += 1

        



if cnt:

    print((N - cnt))

else:

    print((-1))
import sys

read = sys.stdin.read
N, *a = list(map(int, read().split()))
a = [0] + a
seq = []
idx = 1
for i in range(1, N + 1):
    if a[i] == idx:
        seq.append(idx)
        idx += 1
if seq:
    print((N - len(seq)))
else:
    print((-1))

import sys

read = sys.stdin.read
N, *a = list(map(int, read().split()))
cnt = 0
idx = 1
for i in a:
    if i == idx:
        cnt += 1
        idx += 1
if cnt:
    print((N - cnt))
else:
    print((-1))

-a = [0] + a -seq = [] +cnt = 0 -for i in range(1, N + 1): -    if a[i] == idx: -        seq.append(idx) +for i in a: +    if i == idx: +        cnt += 1 -if seq: -    print((N - len(seq))) +if cnt: +    print((N - cnt))