#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const int N = 100005;
int n, i, tab[N], res, act, a, was[N];
int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &tab[i]);
  res = 0;
  act = 0;
  for (i = 0; i < n; i++) {
    scanf("%d", &a);
    was[a] = 1;
    if (a != tab[act])
      res++;
    else {
      act++;
      while (act < n && was[tab[act]]) act++;
    }
  }
  printf("%d\n", res);
  return 0;
}
