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