N,*P=list(map(int,open(0)))

ids=[0]*N

for i in range(N):

	ids[P[i]-1]=i

tmp=inc=1

for i in range(N-1):

	if ids[i]<ids[i+1]:

		tmp+=1

		inc=max(tmp,inc)

	else:

		tmp=1

print((N-inc))
d={}

for x in map(int,open(0)):d[x]=d.get(x-1,0)+1

print((len(d)-max(d.values())))
N, *P = list(map(int, open(0)))
ids = [0] * N
for i in range(N):
    ids[P[i] - 1] = i
tmp = inc = 1
for i in range(N - 1):
    if ids[i] < ids[i + 1]:
        tmp += 1
        inc = max(tmp, inc)
    else:
        tmp = 1
print((N - inc))

d = {}
for x in map(int, open(0)):
    d[x] = d.get(x - 1, 0) + 1
print((len(d) - max(d.values())))

-N, *P = list(map(int, open(0))) -ids = [0] * N -for i in range(N): -    ids[P[i] - 1] = i -tmp = inc = 1 -for i in range(N - 1): -    if ids[i] < ids[i + 1]: -        tmp += 1 -        inc = max(tmp, inc) -    else: -        tmp = 1 -print((N - inc)) +d = {} +for x in map(int, open(0)): +    d[x] = d.get(x - 1, 0) + 1 +print((len(d) - max(d.values())))