N = int(eval(input()))

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



if not(1 in a):

    print((-1))

    exit(0)



l = []

min_num = 0

for i in a:

    if i == min_num + 1:

        l.append(i)

        min_num += 1



print((N-len(l)))
N = int(eval(input()))

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



if not(1 in a):

    print((-1))

    exit(0)



cnt = 0

for i in a:

    if i == cnt + 1:

        cnt += 1



print((N-cnt))
N = int(eval(input()))
a = list(map(int, input().split()))
if not (1 in a):
    print((-1))
    exit(0)
l = []
min_num = 0
for i in a:
    if i == min_num + 1:
        l.append(i)
        min_num += 1
print((N - len(l)))

N = int(eval(input()))
a = list(map(int, input().split()))
if not (1 in a):
    print((-1))
    exit(0)
cnt = 0
for i in a:
    if i == cnt + 1:
        cnt += 1
print((N - cnt))

-l = [] -min_num = 0 +cnt = 0 -    if i == min_num + 1: -        l.append(i) -        min_num += 1 -print((N - len(l))) +    if i == cnt + 1: +        cnt += 1 +print((N - cnt))