n = int(eval(input()))

cnt = 0

queue = []

last = {}

for _ in range(n):

    p = int(eval(input()))

    if p-1 not in list(last.keys()):

        last[p] = len(queue)

        queue.append([p])

        if cnt < 1:

            cnt = 1

    else:

        queue[last[p-1]].append(p)

        last[p] = last[p-1]

        if cnt < len(queue[last[p-1]]):

            cnt = len(queue[last[p-1]])



print((n-cnt))

n = int(eval(input()))

Ps = [int(eval(input()))for _ in range(n)]

p_to_i = {p: i for i, p in enumerate(Ps)}



cnt = x = 1

for p in range(1, n):

    if p_to_i[p] < p_to_i[p+1]:

        x += 1

        if cnt < x:

            cnt = x

    else:

        x = 1

print((n-cnt))

n = int(eval(input()))
cnt = 0
queue = []
last = {}
for _ in range(n):
    p = int(eval(input()))
    if p - 1 not in list(last.keys()):
        last[p] = len(queue)
        queue.append([p])
        if cnt < 1:
            cnt = 1
    else:
        queue[last[p - 1]].append(p)
        last[p] = last[p - 1]
        if cnt < len(queue[last[p - 1]]):
            cnt = len(queue[last[p - 1]])
print((n - cnt))

n = int(eval(input()))
Ps = [int(eval(input())) for _ in range(n)]
p_to_i = {p: i for i, p in enumerate(Ps)}
cnt = x = 1
for p in range(1, n):
    if p_to_i[p] < p_to_i[p + 1]:
        x += 1
        if cnt < x:
            cnt = x
    else:
        x = 1
print((n - cnt))

-cnt = 0 -queue = [] -last = {} -for _ in range(n): -    p = int(eval(input())) -    if p - 1 not in list(last.keys()): -        last[p] = len(queue) -        queue.append([p]) -        if cnt < 1: -            cnt = 1 +Ps = [int(eval(input())) for _ in range(n)] +p_to_i = {p: i for i, p in enumerate(Ps)} +cnt = x = 1 +for p in range(1, n): +    if p_to_i[p] < p_to_i[p + 1]: +        x += 1 +        if cnt < x: +            cnt = x -        queue[last[p - 1]].append(p) -        last[p] = last[p - 1] -        if cnt < len(queue[last[p - 1]]): -            cnt = len(queue[last[p - 1]]) +        x = 1