N = int(eval(input()))

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

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

A = {i:0 for i in range(1,N+1)}

for i in range(N):

    a = P[i]

    if hist[a-1]==0:

        A[a] = a

    else:

        A[a] = A[a-1]

    hist[a] = 1

cmax = 0

for i in range(1,N+1):

    cmax = max(cmax,i-A[i]+1)

print((N-cmax))
N = int(eval(input()))

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

for _ in range(N):

    a = int(eval(input()))

    if A[a-1]==0:

        A[a] = 1

    else:

        A[a] = A[a-1]+1

n = max(A)

print((N-n))
N = int(eval(input()))
P = [int(eval(input())) for _ in range(N)]
hist = [0 for _ in range(N + 1)]
A = {i: 0 for i in range(1, N + 1)}
for i in range(N):
    a = P[i]
    if hist[a - 1] == 0:
        A[a] = a
    else:
        A[a] = A[a - 1]
    hist[a] = 1
cmax = 0
for i in range(1, N + 1):
    cmax = max(cmax, i - A[i] + 1)
print((N - cmax))

N = int(eval(input()))
A = [0 for _ in range(N + 1)]
for _ in range(N):
    a = int(eval(input()))
    if A[a - 1] == 0:
        A[a] = 1
    else:
        A[a] = A[a - 1] + 1
n = max(A)
print((N - n))

-P = [int(eval(input())) for _ in range(N)] -hist = [0 for _ in range(N + 1)] -A = {i: 0 for i in range(1, N + 1)} -for i in range(N): -    a = P[i] -    if hist[a - 1] == 0: -        A[a] = a +A = [0 for _ in range(N + 1)] +for _ in range(N): +    a = int(eval(input())) +    if A[a - 1] == 0: +        A[a] = 1 -        A[a] = A[a - 1] -    hist[a] = 1 -cmax = 0 -for i in range(1, N + 1): -    cmax = max(cmax, i - A[i] + 1) -print((N - cmax)) +        A[a] = A[a - 1] + 1 +n = max(A) +print((N - n))