#include<bits/stdc++.h>
using namespace std;
bool visit[100020];
int main(){
#ifdef PARTHO
freopen("C:\\Users\\parth\\Desktop\\input.txt","r",stdin);
freopen("C:\\Users\\parth\\Desktop\\output.txt","w",stdout);
int start_time = clock();
#endif
queue<int> enter;
int n;
cin >> n;
int value;
for( int i= 0;i<n;i++)
{
cin >> value;
enter.push(value);
}
int fine = 0;
for(int i = 0;!enter.empty();i++)
{
cin >> value;
int top = enter.front();
while(visit[top])
{
enter.pop();
top = enter.front();
}
if(value==top)
{
visit[value] = 1;
enter.pop();
}
else
{
if(!visit[value])
fine++;
visit[value] = 1;
}
}
cout << fine << endl;
#ifdef PARTHO
int end_time = clock();
printf("Time = %f\n",(end_time-start_time+0.0)/CLOCKS_PER_SEC);
#endif
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKIApib29sIHZpc2l0WzEwMDAyMF07CmludCBtYWluKCl7CgogICAgI2lmZGVmIFBBUlRITwogICAgICAgIGZyZW9wZW4oIkM6XFxVc2Vyc1xccGFydGhcXERlc2t0b3BcXGlucHV0LnR4dCIsInIiLHN0ZGluKTsKICAgICAgICBmcmVvcGVuKCJDOlxcVXNlcnNcXHBhcnRoXFxEZXNrdG9wXFxvdXRwdXQudHh0IiwidyIsc3Rkb3V0KTsKICAgICAgICBpbnQgc3RhcnRfdGltZSA9IGNsb2NrKCk7CiAgICAjZW5kaWYKCiAgIHF1ZXVlPGludD4gZW50ZXI7CiAgICBpbnQgbjsKICAgIGNpbiA+PiBuOwogICAgaW50IHZhbHVlOwogICAgZm9yKCBpbnQgaT0gMDtpPG47aSsrKQogICAgewogICAgICAgIGNpbiA+PiB2YWx1ZTsKICAgICAgICBlbnRlci5wdXNoKHZhbHVlKTsKICAgIH0KCiAgICBpbnQgZmluZSA9IDA7CiAgICBmb3IoaW50IGkgPSAwOyFlbnRlci5lbXB0eSgpO2krKykKICAgICAgewogICAgICAgIGNpbiA+PiB2YWx1ZTsKICAgICAgICBpbnQgdG9wID0gZW50ZXIuZnJvbnQoKTsKICAgICAgICB3aGlsZSh2aXNpdFt0b3BdKQogICAgICAgIHsKICAgICAgICAgICAgZW50ZXIucG9wKCk7CiAgICAgICAgICAgIHRvcCA9IGVudGVyLmZyb250KCk7CiAgICAgICAgfQoKICAgICAgICBpZih2YWx1ZT09dG9wKQogICAgICAgIHsKICAgICAgICAgICAgdmlzaXRbdmFsdWVdID0gMTsKICAgICAgICAgICAgZW50ZXIucG9wKCk7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGlmKCF2aXNpdFt2YWx1ZV0pCiAgICAgICAgICAgICAgICBmaW5lKys7CgogICAgICAgICAgICB2aXNpdFt2YWx1ZV0gPSAxOwogICAgICAgICAgICAKICAgICAgICB9CiAgICAgICAgCgogICAgICB9CiAgICAgIGNvdXQgPDwgZmluZSA8PCBlbmRsOwogIAoKICAgICNpZmRlZiBQQVJUSE8KICAgICAgICBpbnQgZW5kX3RpbWUgPSBjbG9jaygpOwogICAgICAgIHByaW50ZigiVGltZSA9ICVmXG4iLChlbmRfdGltZS1zdGFydF90aW1lKzAuMCkvQ0xPQ0tTX1BFUl9TRUMpOwogICAgI2VuZGlmCiAgICByZXR1cm4gMDsKfQo=