#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> ve1, ve2(n + 1);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ve1.push_back(x);
  }
  for (int j = 0; j < n; j++) {
    int x;
    cin >> x;
    ve2[x] = j + 1;
  }
  for (int i = 0; i < n; i++) {
    ve1[i] = ve2[ve1[i]];
  }
  int last = 0;
  for (int i = 0; i < n; i++) {
    if (ve1[i] > last) {
      last = ve1[i];
    } else {
      cout << n - i << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}
