#include <bits/stdc++.h>
using namespace std;
int n, a[200010], b[200010];
int no[200010];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) no[b[i]] = i;
  for (int i = 1; i <= n - 1; i++)
    if (no[a[i + 1]] < no[a[i]]) {
      printf("%d\n", n - i);
      return 0;
    }
  printf("0\n");
  return 0;
}
