#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, a[N], b[N], loc[N];
int main(void) {
  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) loc[b[i]] = i;
  int pre = loc[a[1]], p = 2;
  while (loc[a[p]] > pre) pre = loc[a[p]], ++p;
  printf("%d\n", n - p + 1);
  return 0;
}
