#include <bits/stdc++.h>
int pos[200003], arr1[200003];
int main() {
  int n, i, x, prev;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &arr1[i]);
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    pos[x] = i;
  }
  prev = -1;
  for (i = 0; i < n && pos[arr1[i]] > prev; i++) prev = pos[arr1[i]];
  printf("%d\n", n - i);
  return 0;
}
