#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  long long a[n + 1], b[n + 1], c[n + 1];
  map<long long, long long> mp;
  for (long long i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  for (long long i = 1; i < n + 1; i++) {
    cin >> b[i];
    mp[b[i]] = i;
  }
  for (long long i = 1; i < n + 1; i++) {
    c[i] = mp[a[i]];
  }
  long long maxi = 0, cnt = 0;
  for (long long i = 1; i < n + 1; i++) {
    if (c[i] < maxi) cnt++;
    maxi = max(maxi, c[i]);
  }
  cout << cnt << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
