N=int(input()) A=list(map(int,input().split())) pos=[0 for i in range(N)] for i in range(N): pos[A[i]-1]=i B=list(map(int,input().split())) prev=-1 chunk=0 ans=0 for i in B: if prev>pos[i-1]: chunk+=1 prev=pos[i-1] while chunk>0: ans+=1 chunk//=2 print(ans)