#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n), b(n), c(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) cin >> b[i];
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    mp[b[i]] = i;
  }
  for (long long i = 0; i < n; i++) {
    c[i] = mp[a[i]];
  }
  long long mx = -1;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    if (c[i] < mx) {
      ans++;
    } else {
      mx = c[i];
    }
  }
  cout << ans << "\n";
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long tt = 1;
  while (tt--) {
    solve();
  }
}
