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