#include <bits/stdc++.h>
using namespace std;
int A[200001], B[200001], pos[200001];
int main() {
  int n;
  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]);
    pos[B[i]] = i;
  }
  int i;
  for (i = 2; i <= n; ++i)
    if (pos[A[i]] < pos[A[i - 1]]) break;
  printf("%d\n", n - i + 1);
  return 0;
}
