n = int(eval(input()))

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

ans_lst = []

for ai in a:

    if len(ans_lst) == 0 and ai == 1:

        ans_lst.append(1)

    elif len(ans_lst) > 0 and ans_lst[-1] == ai - 1:

        ans_lst.append(ai)

if len(ans_lst) == 0:

    print((-1))

else:

    print((n - len(ans_lst)))
n = int(eval(input()))

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

ans = 0

for ai in a:

    if ans == ai - 1:

        ans += 1

if ans == 0:

    print((-1))

else:

    print((n-ans))
n = int(eval(input()))
a = list(map(int, input().split()))
ans_lst = []
for ai in a:
    if len(ans_lst) == 0 and ai == 1:
        ans_lst.append(1)
    elif len(ans_lst) > 0 and ans_lst[-1] == ai - 1:
        ans_lst.append(ai)
if len(ans_lst) == 0:
    print((-1))
else:
    print((n - len(ans_lst)))

n = int(eval(input()))
a = list(map(int, input().split()))
ans = 0
for ai in a:
    if ans == ai - 1:
        ans += 1
if ans == 0:
    print((-1))
else:
    print((n - ans))

-ans_lst = [] +ans = 0 -    if len(ans_lst) == 0 and ai == 1: -        ans_lst.append(1) -    elif len(ans_lst) > 0 and ans_lst[-1] == ai - 1: -        ans_lst.append(ai) -if len(ans_lst) == 0: +    if ans == ai - 1: +        ans += 1 +if ans == 0: -    print((n - len(ans_lst))) +    print((n - ans))