#include <bits/stdc++.h>
int M[200009], x[200009], t[200009], v[200009];
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> t[i];
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    M[v[i]] = i;
  }
  for (int i = 1; i <= n; i++) x[i] = M[t[i]];
  bool l = 0;
  for (int i = 2; i <= n; i++) {
    if (x[i] < x[i - 1]) {
      cout << n - i + 1 << endl;
      l = 1;
      break;
    }
  }
  if (!l) cout << 0 << endl;
}
