#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> enter(n + 1);
  vector<long long int> exit(n + 1);
  for (long long int i = 1; i <= n; i++) cin >> enter[i];
  for (long long int i = 1; i <= n; i++) cin >> exit[i];
  vector<long long int> pos(n + 1);
  for (long long int i = 1; i <= n; i++) {
    pos[exit[i]] = i;
  }
  vector<long long int> c(n + 1);
  for (long long int i = 1; i <= n; i++) {
    c[i] = pos[enter[i]];
  }
  long long int mx = -1, ammns = 0;
  for (long long int i = 1; i <= n; i++) {
    if (c[i] > mx)
      mx = c[i];
    else
      ammns++;
  }
  cout << ammns << endl;
}
int main(int argc, const char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int tests = 1;
  while (tests--) {
    solve();
  }
  return 0;
}
