#include <bits/stdc++.h>
using namespace std;
int p1[2 * 100001];
int p2[2 * 100001];
int p[2 * 100001];
void TheSolution(istream& input, ostream& output) {
  int n;
  input >> n;
  for (int i = 1; i <= n; i++) input >> p1[i];
  for (int i = 1; i <= n; i++) input >> p2[i];
  for (int i = 1; i <= n; i++) p[p2[i]] = i;
  for (int i = 1; i <= n - 1; i++) {
    if (p[p1[i + 1]] < p[p1[i]]) {
      output << n - i;
      return;
    }
  }
  output << 0;
}
int main() {
  TheSolution(cin, cout);
  return 0;
}
