#include <bits/stdc++.h>
using namespace std;
long long n, m, k, i, j, a[1000000], b[1000000], x, res = 1;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    cin >> x;
    b[x] = i;
  }
  while (b[a[res]] > b[a[res - 1]]) {
    res++;
  }
  res = n - res;
  cout << res;
}
