n = int(eval(input()))

ppp = list(map(int, (eval(input()) for _ in range(n))))



tmp_f = {}

for p in ppp:

    if p - 1 in tmp_f:

        tmp_f[p] = tmp_f[p - 1] + 1

    else:

        tmp_f[p] = 1



# tmp_b = {}

# for p in ppp[::-1]:

#     if p + 1 in tmp_b:

#         tmp_b[p] = tmp_b[p + 1] + 1

#     else:

#         tmp_b[p] = 1



cnt = max(tmp_f.values())

print((n - cnt))

n = int(eval(input()))

ppp = list(map(int, (eval(input()) for _ in range(n))))



tmp = [0] * (n + 1)

for p in ppp:

    tmp[p] = tmp[p - 1] + 1



print((n - max(tmp)))

n = int(eval(input()))
ppp = list(map(int, (eval(input()) for _ in range(n))))
tmp_f = {}
for p in ppp:
    if p - 1 in tmp_f:
        tmp_f[p] = tmp_f[p - 1] + 1
    else:
        tmp_f[p] = 1
# tmp_b = {}
# for p in ppp[::-1]:
#     if p + 1 in tmp_b:
#         tmp_b[p] = tmp_b[p + 1] + 1
#     else:
#         tmp_b[p] = 1
cnt = max(tmp_f.values())
print((n - cnt))

n = int(eval(input()))
ppp = list(map(int, (eval(input()) for _ in range(n))))
tmp = [0] * (n + 1)
for p in ppp:
    tmp[p] = tmp[p - 1] + 1
print((n - max(tmp)))

-tmp_f = {} +tmp = [0] * (n + 1) -    if p - 1 in tmp_f: -        tmp_f[p] = tmp_f[p - 1] + 1 -    else: -        tmp_f[p] = 1 -# tmp_b = {} -# for p in ppp[::-1]: -#     if p + 1 in tmp_b: -#         tmp_b[p] = tmp_b[p + 1] + 1 -#     else: -#         tmp_b[p] = 1 -cnt = max(tmp_f.values()) -print((n - cnt)) +    tmp[p] = tmp[p - 1] + 1 +print((n - max(tmp)))