#include <bits/stdc++.h>
using namespace std;
const long long M = 1e5 + 5;
long long n, a[M], b[M], id[M];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  vector<pair<long long, long long> > v;
  for (long long i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    a[x] = i;
  }
  for (long long i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    b[i] = a[x];
  }
  long long ans = 0, mn = b[n];
  for (long long i = n - 1; i > 0; i--) {
    ans += (b[i] > mn);
    mn = min(mn, b[i]);
  }
  cout << ans;
  return 0;
}
