N = int(eval(input()))

P = [int(eval(input())) for _ in range(N)]



S = [0 for _ in range(N+1)]



for i in range(N):

    if S[P[i]-1]!=0:

        S[P[i]] = S[P[i]-1]+1

    else:

        S[P[i]] = 1

    

print((N-max(S)))
N = int(eval(input()))

P = [int(eval(input())) for _ in range(N)]



S = [0]*(N+1)



for p in P:

    S[p] = S[p-1]+1



print((N-max(S)))
N = int(eval(input()))
P = [int(eval(input())) for _ in range(N)]
S = [0 for _ in range(N + 1)]
for i in range(N):
    if S[P[i] - 1] != 0:
        S[P[i]] = S[P[i] - 1] + 1
    else:
        S[P[i]] = 1
print((N - max(S)))

N = int(eval(input()))
P = [int(eval(input())) for _ in range(N)]
S = [0] * (N + 1)
for p in P:
    S[p] = S[p - 1] + 1
print((N - max(S)))

-S = [0 for _ in range(N + 1)] -for i in range(N): -    if S[P[i] - 1] != 0: -        S[P[i]] = S[P[i] - 1] + 1 -    else: -        S[P[i]] = 1 +S = [0] * (N + 1) +for p in P: +    S[p] = S[p - 1] + 1