#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long> enter(n);
  vector<long long> exit(n);
  map<long long, long long> mapping;
  for (int i = 0; i < n; i++) {
    cin >> enter[i];
    mapping[enter[i]] = i;
  }
  long long begin = 0;
  long long end = 0;
  long long fined = 0;
  vector<long long> act(n);
  for (int i = 0; i < n; i++) {
    cin >> exit[i];
    long long thi = mapping[exit[i]];
    act[i] = thi;
  }
  long long up = 0;
  long long min = 10000000000;
  for (int i = n - 1; i >= 0; i--) {
    if (act[i] < min) {
      min = act[i];
    }
    if (act[i] > min) fined++;
  }
  cout << fined << "\n";
}
