#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
template <typename T>
void read(T &x) {
  int p = 1;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') p = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - 48;
    c = getchar();
  }
  x *= p;
}
int a[N], b[N], pos[N];
int main() {
  int n, mx, ans = 0;
  read(n);
  for (int i = 1; i <= n; i++) read(a[i]), pos[a[i]] = i;
  for (int i = 1; i <= n; i++) read(b[i]), b[i] = pos[b[i]];
  mx = n + 1;
  for (int i = n; i >= 1; i--) {
    if (mx < b[i]) ++ans;
    mx = min(mx, b[i]);
  }
  cout << ans << "\n";
  return 0;
}
