#include <bits/stdc++.h>
using namespace std;
const long maxN=1e5+3;
vector<int> b;
int pos[maxN];

int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
long long n; cin>>n;
for(long long i=0;i<n;i++){
	long long p; cin>>p;
	pos[p]=i;
}
for(long long i=0;i<n;i++){
	long long p; cin>>p; b.push_back(p);
}
int br=0,lstindl=-2;
for(long long ir=0;ir<n;ir++){
	if(lstindl+1==pos[b[ir]]) {
		lstindl++;
		continue;
	}
	br++;
	lstindl=pos[b[ir]];
}
cout<<br<<'\n';
return 0;
}