#include <bits/stdc++.h>
using namespace std;
int n;
int a[200010], b[200010];
int cal() {
  int i = 1, j = 1;
  while (i <= n && j <= n) {
    if (a[i] == b[j]) {
      i++;
      j++;
    } else
      j++;
  }
  return n - i + 1;
}
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]);
  printf("%d\n", cal());
  return 0;
}
