#include <iostream>
#include <cstdio>
using namespace std;
int n, l, r, mid, cnt, ans;
int p1[100005], p2[100005], mp[100005], dp[100005]={1145140};
int main(){
scanf("%d", &n);
for(int i=1; i<=n; i++)scanf("%d", &p1[i]), mp[p1[i]]=i;
for(int i=1; i<=n; i++)scanf("%d", &p2[i]), p2[i]=mp[p2[i]];
for(int i=1; i<=n; i++){
l=0, r=ans;
while(l<=r){
mid=(l+r)/2;
if(dp[mid]>=p2[i]){
cnt=mid;
l=mid+1;
}
else r=mid-1;
}
ans=max(ans,cnt+1);
dp[cnt+1]=p2[i];
}
printf("%d", ans);
return 0;
}