N=int(input()) P=list(map(int,input().split())) Q=list(map(int,input().split())) if P==Q: print(0) exit() A=[(P[i],i) for i in range(N)] A.sort() B=[-1]*N for i in range(N): B[A[Q[i]-1][1]]=i+1 B_INV=[-1]*N for i in range(N): B_INV[B[i]-1]=i block=1 for i in range(N-1): if B_INV[i]>B_INV[i+1]: block+=1 ANS=0 while block: ANS+=1 block//=2 print(ANS)