import sys



n=int(eval(input()))

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



ans = 0

_find = 1

before = 0



if not 1 in set(a):

    print((-1))

    sys.exit()



for i in range(n):

    if a[i]==_find:

        ans += i-before

        _find += 1

        before = i+1



print((ans+n-before))
n=int(eval(input()))

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



ans = 0

block = 1

no_block = False



for i in range(n):   

    if a[i]!=block:

        ans+=1

    else:

        no_block = True

        block+=1



if no_block is False:

    print((-1))

else:

    print(ans)
import sys

n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
_find = 1
before = 0
if not 1 in set(a):
    print((-1))
    sys.exit()
for i in range(n):
    if a[i] == _find:
        ans += i - before
        _find += 1
        before = i + 1
print((ans + n - before))

n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
block = 1
no_block = False
for i in range(n):
    if a[i] != block:
        ans += 1
    else:
        no_block = True
        block += 1
if no_block is False:
    print((-1))
else:
    print(ans)

-import sys - -_find = 1 -before = 0 -if not 1 in set(a): +block = 1 +no_block = False +for i in range(n): +    if a[i] != block: +        ans += 1 +    else: +        no_block = True +        block += 1 +if no_block is False: -    sys.exit() -for i in range(n): -    if a[i] == _find: -        ans += i - before -        _find += 1 -        before = i + 1 -print((ans + n - before)) +else: +    print(ans)