#include <bits/stdc++.h>
using namespace std;
int n;
int a[200005];
int b[200005];
int c[200005];
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]);
    c[b[i]] = i;
  }
  int mx = 0;
  int sol = n;
  for (int i = 1; i <= n; i++) {
    if (c[a[i]] < mx) break;
    mx = c[a[i]];
    sol--;
  }
  printf("%d\n", sol);
  return 0;
}
