N = int(eval(input()))

src = [int(eval(input()))-1 for i in range(N)]

ids = [None] * N

for i,a in enumerate(src):

    ids[a] = i



longest = seq = 1

for i1,i2 in zip(ids, ids[1:]):

    if i1 < i2:

        seq += 1

    else:

        longest = max(longest, seq)

        seq = 1

longest = max(longest, seq)

print((N - longest))

N = int(eval(input()))

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



D = {p:i for i,p in enumerate(P)}

pv = N

l = seq = 0

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

    nx = D[n]

    if pv < nx:

        seq += 1

    else:

        l = max(l,seq)

        seq = 1

    pv = nx

l = max(l, seq)



print((N - l))
N = int(eval(input()))
src = [int(eval(input())) - 1 for i in range(N)]
ids = [None] * N
for i, a in enumerate(src):
    ids[a] = i
longest = seq = 1
for i1, i2 in zip(ids, ids[1:]):
    if i1 < i2:
        seq += 1
    else:
        longest = max(longest, seq)
        seq = 1
longest = max(longest, seq)
print((N - longest))

N = int(eval(input()))
P = [int(eval(input())) for i in range(N)]
D = {p: i for i, p in enumerate(P)}
pv = N
l = seq = 0
for n in range(1, N + 1):
    nx = D[n]
    if pv < nx:
        seq += 1
    else:
        l = max(l, seq)
        seq = 1
    pv = nx
l = max(l, seq)
print((N - l))

-src = [int(eval(input())) - 1 for i in range(N)] -ids = [None] * N -for i, a in enumerate(src): -    ids[a] = i -longest = seq = 1 -for i1, i2 in zip(ids, ids[1:]): -    if i1 < i2: +P = [int(eval(input())) for i in range(N)] +D = {p: i for i, p in enumerate(P)} +pv = N +l = seq = 0 +for n in range(1, N + 1): +    nx = D[n] +    if pv < nx: -        longest = max(longest, seq) +        l = max(l, seq) -longest = max(longest, seq) -print((N - longest)) +    pv = nx +l = max(l, seq) +print((N - l))