#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n], b[n];
  map<int, int> mp;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
    mp[b[i]] = i;
  }
  for (long long i = 0; i < n; i++) a[i] = mp[a[i]];
  int id = 1;
  while (id < n && a[id] > a[id - 1]) id++;
  cout << n - id << "\n";
  return 0;
}
