#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    v = v * 10 + c - '0';
    c = getchar();
  }
  return v * f;
}
const int Maxn = 100005;
int n, a[Maxn], b[Maxn];
int ot[Maxn];
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]), ot[b[i]] = i;
  int Mx = 0, ans = 0;
  for (int i = 1; i <= n; i++) {
    if (Mx > ot[a[i]]) {
      ans++;
    }
    Mx = max(Mx, ot[a[i]]);
  }
  printf("%d\n", ans);
  return 0;
}
