#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n;
    cin >> n;
    vector<long long int> a(n), b(n);
    map<long long, long long> tr;
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (long long int i = 0; i < n; i++) {
      cin >> b[i];
      tr[b[i]] = i + 1;
    }
    for (long long int i = 0; i < n; i++) a[i] = tr[a[i]];
    vector<long long int> tmp;
    long long it = 0;
    while (a[it] != n) {
      tmp.push_back(a[it]);
      it++;
    }
    sort((tmp).begin(), (tmp).end());
    long long ans = 0;
    long long fl = 0;
    for (long long int i = 0; i < (long long int)tmp.size(); i++) {
      if (a[i] < a[i + 1]) {
        fl++;
      } else {
        fl++;
        break;
      }
    }
    if (fl != (long long int)tmp.size()) {
      ans = n - fl;
    } else {
      ans = n - (long long int)tmp.size() - 1;
    }
    cout << ans << "\n";
  }
  return 0;
}
