#include <bits/stdc++.h>
using namespace std;
int n;
int a[200002];
int b[200002];
int bb[200002];
int aa[200002];
bool ok[200002];
int bit[200002];
void add(int i, int x) {
  i++;
  while (i < 200002) {
    bit[i] += x;
    i += i & -i;
  }
}
int sum(int i) {
  i++;
  int summ = 0;
  while (i > 0) {
    summ += bit[i];
    i -= i & -i;
  }
  return summ;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    aa[a[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
    bb[b[i]] = i;
  }
  int countt = 0;
  for (int i = 1; i < n; i++) {
    if (bb[a[i - 1]] > bb[a[i]]) {
      countt = n - i;
      break;
    }
  }
  printf("%d\n", countt);
  return 0;
}
