#include <vector>
#include <iostream>
using namespace std;
int choc[100000],choc2[100000],refere[100000];
int main(){
int n;
cin>>n;

for(int a=0;a<n;a++){
cin>>choc[a];
refere[choc[a]]=a;}
for(int a=0;a<n;a++){
cin>>choc2[a];

}
int cons=0;
int n2=n;
int x;
for(int a=0;a<n;a++){
bool e=true;
if(cons==0){
    x=refere[choc2[a]];
}
if(x+cons>=n){e=false;}
        if(choc2[a]==choc[x+cons] and e a!=n-1){
            cons++;
//cout<<cons<<" ";
        }
        if(choc2[a+1]!=choc[x+cons] or !e or a==n-1){
//cout<<cons;
        n2=n2-(cons-1);
        cons=0;}

}
cout<<n2;
return 0;}
//5
//4 3 2 5 1
//1 2 5 3 4
//
//5
//1 2 3 4 5
//1 2 3 4 5
