#include <bits/stdc++.h>   using namespace std;   int in[100005];   int in2[100005];   int remlocate[100005];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> in[i];     }     for (int i = 0; i < n; ++i) {       cin >> in2[i];       remlocate[in2[i]] = i;     }     int go1 = n - 1;     int go2 = n - 1;     int cnt = 0;     for (int i = 0; i < n; ++i) {       while (in2[go2] == 0) {         go2--;       }       if (in[go1] != in2[go2]) {         cnt++;         in2[remlocate[in[go1]]] = 0;         go1--;       } else {         go1--;         go2--;       }     }     cout << cnt << endl;     return 0;   }   