#include <bits/stdc++.h>
using namespace std;
const double eps = 1.0e-11;
const double pi = acos(-1.0);
int main() {
  int n;
  cin >> n;
  vector<int> in(n), out(n);
  for (long long i = 0; i < n; i++) cin >> in[i], in[i];
  for (long long i = 0; i < n; i++) cin >> out[i], out[i];
  vector<int> comp(n + 1);
  for (long long i = 0; i < n; i++) {
    comp[out[i]] = i;
  }
  int pos = 1;
  while (pos < n && comp[in[pos - 1]] < comp[in[pos]]) ++pos;
  cout << n - pos << endl;
  return 0;
}
