N = int(eval(input()))

a = [0 for i in range(N)]

chain = [0 for i in range(N+1)]

for i in range(N):

  a[i] = int(eval(input()))

  chain[a[i]] = chain[a[i]-1]+1

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

chain = [0 for i in range(N+1)]

for i in range(N):

  a = int(eval(input()))

  chain[a] = chain[a-1]+1

print((N-max(chain)))
N = int(eval(input()))
a = [0 for i in range(N)]
chain = [0 for i in range(N + 1)]
for i in range(N):
    a[i] = int(eval(input()))
    chain[a[i]] = chain[a[i] - 1] + 1
print((N - max(chain)))

N = int(eval(input()))
chain = [0 for i in range(N + 1)]
for i in range(N):
    a = int(eval(input()))
    chain[a] = chain[a - 1] + 1
print((N - max(chain)))

-a = [0 for i in range(N)] -    a[i] = int(eval(input())) -    chain[a[i]] = chain[a[i] - 1] + 1 +    a = int(eval(input())) +    chain[a] = chain[a - 1] + 1