#include <bits/stdc++.h>
using namespace std;
const int MN = 2 * 100000 + 20;
int p1[MN], p2[MN], d[MN];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> p1[i];
  for (int i = 0; i < n; i++) cin >> p2[i];
  for (int i = 0; i < n; i++) d[p2[i]] = i + 1;
  for (int i = 0; i < n; i++)
    if (d[p1[i]] > d[p1[i + 1]]) {
      cout << n - i - 1 << endl;
      return 0;
    }
  cout << 0 << endl;
  return 0;
}
