N = int(eval(input()))

li = [int(zz) for zz in input().split()]



count = 1

ans = 0

ind = 0

while ind < N:

    if li[ind] == count:

        count += 1

        ans += 1

    ind += 1



if ans != 0:

    print((N-ans))

else:

    print((-1))

N = int(eval(input()))

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



ans = 0

c = 1

for i in range(N):

    if A[i] == c:

        c += 1

    else:

        ans += 1



if c == 1:

    print((-1))

else:

    print(ans)

N = int(eval(input()))
li = [int(zz) for zz in input().split()]
count = 1
ans = 0
ind = 0
while ind < N:
    if li[ind] == count:
        count += 1
        ans += 1
    ind += 1
if ans != 0:
    print((N - ans))
else:
    print((-1))

N = int(eval(input()))
A = [int(i) for i in input().split()]
ans = 0
c = 1
for i in range(N):
    if A[i] == c:
        c += 1
    else:
        ans += 1
if c == 1:
    print((-1))
else:
    print(ans)

-li = [int(zz) for zz in input().split()] -count = 1 +A = [int(i) for i in input().split()] -ind = 0 -while ind < N: -    if li[ind] == count: -        count += 1 +c = 1 +for i in range(N): +    if A[i] == c: +        c += 1 +    else: -    ind += 1 -if ans != 0: -    print((N - ans)) +if c == 1: +    print((-1)) -    print((-1)) +    print(ans)