n = int(eval(input()))

a = [int(i) for i in input().split()]

c = 0

d = 0

for i in range(n):

    for j in range(c, n):

        if i + 1 == a[j]:

            c = j

            d += 1

            break

    else:

        break

    if c == n - 1:

        break

if 1 not in a:

    print((-1))

else:

    print((n - d))
n = int(eval(input()))

a = [int(i) for i in input().split()]

if 1 in a:

    j = 0

    for ai in a:

        if ai == j + 1:

            j += 1

    print((n - j))

else:

    print((-1))
n = int(eval(input()))
a = [int(i) for i in input().split()]
c = 0
d = 0
for i in range(n):
    for j in range(c, n):
        if i + 1 == a[j]:
            c = j
            d += 1
            break
    else:
        break
    if c == n - 1:
        break
if 1 not in a:
    print((-1))
else:
    print((n - d))

n = int(eval(input()))
a = [int(i) for i in input().split()]
if 1 in a:
    j = 0
    for ai in a:
        if ai == j + 1:
            j += 1
    print((n - j))
else:
    print((-1))

-c = 0 -d = 0 -for i in range(n): -    for j in range(c, n): -        if i + 1 == a[j]: -            c = j -            d += 1 -            break -    else: -        break -    if c == n - 1: -        break -if 1 not in a: +if 1 in a: +    j = 0 +    for ai in a: +        if ai == j + 1: +            j += 1 +    print((n - j)) +else: -else: -    print((n - d))