#include <bits/stdc++.h>
using namespace std;
const int MAX = 200005;
int a[MAX];
int b[MAX];
int main(void) {
  int n, v;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &v);
    b[v] = i;
  }
  int p = 1;
  for (; p < n && b[a[p]] < b[a[p + 1]]; ++p)
    ;
  printf("%d\n", n - p);
  return 0;
}
