#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, xx = 0, z = 0;
  cin >> n;
  int a[n], p[n];
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    p[x] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (p[a[i]] < z) xx++;
    z = max(z, p[a[i]]);
  }
  return cout << xx, 0;
}
