#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long n, a[N], ans, b[N], maxi;
int main() {
  vector<long long> v;
  map<long long, long long> mp;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long i = 1; i <= n; i++) {
    cin >> b[i];
    mp[b[i]] = i;
  }
  for (long long i = 1; i <= n; i++) {
    if (maxi > mp[a[i]]) ans++;
    maxi = max(maxi, mp[a[i]]);
  }
  cout << ans;
  return 0;
}
