#include <bits/stdc++.h>
int mas1[200010], mas2[200010], n;
int main(int argc, const char* argv[]) {
  scanf("%d", &n);
  int help;
  for (int i = 0; i <= 200000; i++) {
    mas1[i] = 0;
    mas2[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", mas1 + i);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &help);
    mas2[help] = i + 1;
  }
  int k = 1;
  for (; k < n; k++) {
    if (mas2[mas1[k]] < mas2[mas1[k - 1]]) break;
  }
  printf("%d\n", n - k);
  return 0;
}
