#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> p(n + 1), s(n + 1), rp(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
    rp[p[i]] = i;
  }
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
    p[rp[s[i]]] = i;
  }
  int cnt = 1;
  for (int i = 2; i <= n; ++i) {
    if (p[i] > p[i - 1]) {
      cnt++;
    } else {
      break;
    }
  }
  cout << setprecision(15) << n - cnt << endl;
  return 0;
}
