#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int n, mex = 1, ans = 0;
  set<int> s;
  cin >> n;
  vector<int> v(n);
  map<int, int> m;
  for (int i = 0; i < n; ++i) cin >> v[i], m[v[i]] = i + 1;
  for (int i = 0; i < n; ++i) {
    int d;
    cin >> d;
    int x = m[d];
    while (s.count(mex)) mex++;
    if (mex != x) ans++;
    s.insert(x);
  }
  cout << ans;
  return 0;
}
