#include <bits/stdc++.h>
using namespace std;
const int N_ = 200005;
int N, A[N_], B[N_];
long long res;
int par[N_], size[N_];
int get(int x) { return (par[x] == x) ? x : (par[x] = get(par[x])); }
int main() {
  int i, j, k;
  scanf("%d", &N);
  for (i = 1; i <= N; i++) scanf("%d", A + i);
  for (i = 1; i <= N; i++) scanf("%d", &k), B[k] = i;
  for (i = 1; i <= N; i++) A[i] = B[A[i]];
  for (i = 1; i <= N; i++)
    if (A[i] < A[i - 1]) break;
  printf("%d\n", N - i + 1);
  return 0;
}
