#include <bits/stdc++.h>
using namespace std;
int ind[200000], ex[200000], m = 0;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    ind[a] = n + 1 - i;
  }
  int q = 0;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    ex[n + 1 - i] = ind[a];
  }
  for (int i = 1; i <= n; i++) {
    if (ex[i] < m) q++;
    m = max(ex[i], m);
    m = max(m, i);
  }
  cout << q << endl;
  return 0;
}
