#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
template <class T>
void mxi(T& a, const T& b) {
  a = max(a, b);
}
template <class T>
void mni(T& a, const T& b) {
  a = min(a, b);
}
long double EPS = 1e-9;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
vector<int> a, ind;
void solve() {
  int n;
  cin >> n;
  a.resize(n), ind.resize(n + 1);
  for (int i = 0; i < (n); i++) cin >> a[i];
  for (int i = 0; i < (n); i++) {
    int x;
    cin >> x;
    ind[x] = i;
  }
  set<int> seen;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if ((long long)(seen).size()) {
      if (seen.upper_bound(ind[a[i]]) != seen.end()) {
        ans = n - i;
        break;
      }
    }
    seen.insert(ind[a[i]]);
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t, tab;
  t = 1;
  tab = t;
  while (t--) {
    solve();
  }
  cerr << ((double)clock() / CLOCKS_PER_SEC);
}
