#include <bits/stdc++.h>
using namespace std;
int n, ans, x, mn = 100001;
vector<int> A, B;
map<int, int> Ps1, Ps2, Mn;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    Ps1[x] = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> x;
    Ps2[i] = Ps1[x];
  }
  for (int i = n - 1; i >= 0; i--) {
    mn = min(mn, Ps2[i]);
    Mn[i] = mn;
  }
  for (int i = 0; i < n; i++) {
    if (Ps2[i] > Mn[i]) ans++;
  }
  cout << ans << endl;
}
