#include <vector>
#include <iostream>
using namespace std;
int choc[100000],choc2[100000],refere[100000];
int main(){
int n;
cin>>n;
int cons=-1;
for(int a=0;a<n;a++){
cin>>choc[a];
refere[choc[a]]=a;}
n--;
for(int a=0;a<=n;a++){
cin>>choc2[a];
if(refere[choc2[a]]==a){
cons++;
}else if(cons!=-1) {
n=n-cons;
cons=0;
}
}
cout<<n;
return 0;}
