#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n, 0);
  vector<int> p(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    p[x - 1] = i;
  }
  int ii = 1;
  while (ii < n && p[a[ii - 1]] < p[a[ii]]) {
    ii++;
  }
  cout << n - ii << endl;
  return 0;
}
