#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  long n;
  scanf("%ld", &n);
  long a[n];
  for (long x, i = 0; i < n; i++) {
    scanf("%ld", &x);
    a[x] = i;
  }
  long ans = 0, last = -1;
  for (long x, i = 0; i < n; i++) {
    scanf("%ld", &x);
    if (i - ans != a[x]) ans++;
  }
  printf("%ld\n", ans);
  return EXIT_SUCCESS;
}
