#include <bits/stdc++.h>
using namespace std;
int n, a[200111], val, pos[200111];
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", &val);
    pos[val] = i;
  }
  for (int i = (1), _b = (n - 1); i <= _b; i++)
    if (pos[a[i]] < pos[a[i - 1]]) {
      printf("%d\n", n - i);
      return 0;
    }
  puts("0");
  return 0;
}
