#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int a[N], b[N];
int main() {
  int n, x, ans = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &x), a[x] = i;
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  int mi = n + 1;
  for (int i = n; i >= 1; i--) {
    if (a[b[i]] > mi)
      ans++;
    else
      mi = a[b[i]];
  }
  printf("%d", ans);
  return 0;
}
