#include <bits/stdc++.h>
using namespace std;
int n, i, j;
int a[200001], b[200001];
int main() {
  cout.setf(ios ::fixed | ios ::showpoint);
  cout.precision(9);
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) {
    cin >> b[i];
  }
  i = 1;
  j = 1;
  while (i <= n && j <= n) {
    if (j <= n && a[i] != b[j]) j++;
    if (j <= n && a[i] == b[j]) i++;
  }
  i--;
  cout << n - i;
  return 0;
}
