#include <bits/stdc++.h>
int n, data[2][200000];
int ind[200001];
int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", data[0] + i);
  for (int i = 0; i < n; i++) {
    scanf("%d", data[1] + i);
    ind[data[1][i]] = i;
  }
  int ans = 0;
  int last = -1;
  for (int i = 0; i < n; i++) {
    if (ind[data[0][i]] < last) {
      ans = n - i;
      break;
    }
    last = ind[data[0][i]];
  }
  printf("%d\n", ans);
  return 0;
}
