#include <bits/stdc++.h>
int a[200010], b[200010];
int c[200010];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  for (int i = 0; i < n; i++) scanf("%d", b + i);
  for (int i = 0; i < n; i++) c[b[i]] = i;
  int ans = 0;
  int p = -1;
  for (int i = 0; i < n; i++) {
    a[i] = c[a[i]];
  }
  ans = n;
  int k = 1;
  while (k < n && a[k] > a[k - 1]) ++k;
  printf("%d\n", ans - k);
  return 0;
}
