# coding: utf-8

N = int(eval(input()))

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

l = [0]

ans = 0

for i in range(N):

    if l[-1] + 1 != A[i]:

        ans += 1

    else:

        l.append(A[i])

if l[-1] == 0:

    print((-1))

else:

    print(ans)
# coding: utf-8

N = int(eval(input()))

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

ans = 0

now = 1

for i in range(N):

    if now == A[i]:

        now += 1

    else:

        ans += 1

if now == 1 and N != 1:

    print((-1))

else:

    print(ans)
# coding: utf-8
N = int(eval(input()))
A = list(map(int, input().split()))
l = [0]
ans = 0
for i in range(N):
    if l[-1] + 1 != A[i]:
        ans += 1
    else:
        l.append(A[i])
if l[-1] == 0:
    print((-1))
else:
    print(ans)

# coding: utf-8
N = int(eval(input()))
A = list(map(int, input().split()))
ans = 0
now = 1
for i in range(N):
    if now == A[i]:
        now += 1
    else:
        ans += 1
if now == 1 and N != 1:
    print((-1))
else:
    print(ans)

-l = [0] +now = 1 -    if l[-1] + 1 != A[i]: +    if now == A[i]: +        now += 1 +    else: -    else: -        l.append(A[i]) -if l[-1] == 0: +if now == 1 and N != 1: