#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], b[n], i, res = 0, t[n];
  unordered_map<int, int> m1, m2;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    m1[a[i]] = i;
  }
  bool f = 0;
  for (i = 0; i < n; i++) {
    cin >> b[i];
    t[i] = m1[b[i]];
  }
  int min = t[n - 1];
  for (i = n - 2; i >= 0; i--) {
    if (t[i] > min)
      res++;
    else
      min = t[i];
  }
  cout << res;
  return 0;
}
