#include <bits/stdc++.h>
const long long INF = (long long)1e18 + 18;
const long long maxn = (long long)1e6 + 6;
using namespace std;
long long n;
signed main() {
  cin >> n;
  long long a[n], c[n], b[maxn];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < n; i++) {
    long long inp;
    cin >> inp;
    b[inp] = i + 1;
  }
  for (long long i = 0; i < n; i++) {
    c[i] = b[a[i]];
  }
  long long fine = 0, maxx = c[0];
  for (long long i = 0; i < n; i++) {
    if (c[i] < maxx) {
      fine++;
    }
    maxx = max(maxx, c[i]);
  }
  cout << fine;
  return 0;
}
