#include <bits/stdc++.h>
using namespace std;
int a[200100], b[200100];
set<pair<int, int> > st;
set<pair<int, int> >::iterator it;
int main() {
  int n, Max = 0, i, k = 0, M;
  cin >> n;
  M = n;
  for (i = 0; i < n; i++) cin >> a[i];
  for (i = 0; i < n; i++) cin >> b[i];
  for (i = 0; i < n; i++) st.insert(make_pair(b[i], i));
  int q = 0, l = -1;
  for (i = 0; i < n; i++) {
    it = st.lower_bound(make_pair(a[i], -1));
    if (it->second > l) {
      q++;
      l = it->second;
    } else
      break;
  }
  cout << n - q;
  return 0;
}
