n = int(eval(input()))

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

cnt = 0

for i in range(n):

  if a[i] == cnt+1:

    cnt += 1

print((-1 if cnt == 0 else n-cnt))
n = int(eval(input()))

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



now = 1

for x in a:

  if x == now:

    now += 1

    

print((-1 if now == 1 else n-now+1))
n = int(eval(input()))
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
    if a[i] == cnt + 1:
        cnt += 1
print((-1 if cnt == 0 else n - cnt))

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

-cnt = 0 -for i in range(n): -    if a[i] == cnt + 1: -        cnt += 1 -print((-1 if cnt == 0 else n - cnt)) +now = 1 +for x in a: +    if x == now: +        now += 1 +print((-1 if now == 1 else n - now + 1))