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