#include <bits/stdc++.h>
using namespace std;
int n, t, a[200000 + 1], b[200000 + 1], pos[200000 + 1], c, res(0);
int main() {
  scanf("%d", &n);
  for (int i = (1), _b = (n); i <= _b; i++) scanf("%d", &a[i]);
  for (int i = (1), _b = (n); i <= _b; i++) scanf("%d", &b[i]);
  for (int i = (1), _b = (n); i <= _b; i++) pos[b[i]] = i;
  t = 0;
  for (int i = (1), _b = (n); i <= _b; i++) {
    if (t <= pos[a[i]])
      t = pos[a[i]];
    else {
      res = n - i + 1;
      break;
    }
  }
  printf("%d\n", res);
  return 0;
}
