#include <bits/stdc++.h>
using namespace std;
int n, a[200001], p[200001], f[200001], b[200001], l, r, ans, add;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    p[a[i]] = i;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i]);
    f[p[b[i]]] = p[b[i]] - i;
  }
  l = -1;
  r = n - 1;
  while (l < r && f[l + 1] == 0) ++l;
  while (r > l) {
    --r;
    ++add;
    while (l < r && f[l + 1] + add == 0) ++l;
    ++ans;
  }
  printf("%d", ans);
  return 0;
}
