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