#include <bits/stdc++.h>
using namespace std;
int n, m, a[200005], b[200005], c[200005], ans;
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", &m);
    b[m] = i;
  }
  for (int i = 1; i <= n; i++) {
    c[i] = b[a[i]];
  }
  for (int i = 2; i <= n; i++) {
    if (c[i - 1] > c[i]) {
      ans = n - i + 1;
      break;
    }
  }
  printf("%d", ans);
  return 0;
}
