#include <bits/stdc++.h>
using namespace std;
int n;
int a[300000], b[300000], ord[300000];
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]), ord[b[i]] = i;
  for (int i = 1; i <= n; ++i) a[i] = ord[a[i]];
  int j = 1;
  while (j < n && a[j + 1] > a[j]) ++j;
  printf("%d", n - j);
  return 0;
}
