#include<iostream>
using namespace std;
int n,ans;
const int MAXN = 1e5+5;
int a[MAXN],b[MAXN],pos[MAXN];
int main(){
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++){
        cin>>b[i];
        pos[b[i]]=i;
    }
    for(int i=0;i<n;){
        int ind=pos[a[i]];
        while(a[i]==b[ind] and ind!=n){
            i++; ind++;
            //cout<<a[i]<<" "<<b[ind]<<" "<<i<<" "<<ind<<"\n";
        }
        ans++;
    }
    cout<<ans<<"\n";
    return 0;
}
