#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], b[n], c[n];
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    m[b[i]] = i + 1;
  }
  for (int i = 0; i < n; i++) {
    c[i] = m[a[i]];
  }
  int ans = 0;
  int mx = c[0];
  for (int i = 1; i < n; i++) {
    if (c[i] < mx) ans++;
    mx = max(c[i], mx);
  }
  cout << ans << endl;
}
