#include <bits/stdc++.h>
using namespace std;
int n;
int a[200005];
int b[200005];
int p[200005];
int main() {
  scanf("%d", &n);
  for (int(i) = 0, _n = (n); (i) < _n; (i)++) scanf("%d", &a[i]);
  for (int(i) = 0, _n = (n); (i) < _n; (i)++) scanf("%d", &b[i]);
  for (int(i) = 0, _n = (n); (i) < _n; (i)++) p[b[i]] = i;
  int ans = 0;
  for (int(i) = 0, _n = (n - 1); (i) < _n; (i)++)
    if (p[a[i]] > p[a[i + 1]]) {
      ans = n - i - 1;
      break;
    }
  printf("%d\n", ans);
  return 0;
}
