#include <bits/stdc++.h>
int i, j, n, m;
int p[300000], q[300000];
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &j);
    q[j] = i;
  }
  i = 0;
  int ans = 0;
  for (j = 1; j <= n; j++) {
    if (q[p[j]] > i) {
      i = q[p[j]];
      ans++;
    } else
      break;
  }
  printf("%d\n", n - ans);
  return 0;
}
