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