#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> v(n), w(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  for (int i = 0; i < n; i++) cin >> w[i];
  vector<bool> memo(n, false);
  int j = n - 1;
  int res = 0;
  int a = 0, b = 0;
  while (a < n && b < n) {
    if (v[a] == w[b]) {
      a++;
      b++;
      continue;
    }
    if (memo[w[b]]) {
      b++;
      continue;
    }
    do {
      memo[v[j--]] = true;
      res++;
    } while (j >= -1 && v[j + 1] != w[b]);
    b++;
  }
  cout << res;
  return 0;
}
