#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> initial(n + 1);
  vector<int> final(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> initial[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> final[i];
  }
  vector<int> indirection(n + 1);
  for (int i = 1; i <= n; i++) {
    indirection[final[i]] = i;
  }
  vector<int> initialModified(n + 1);
  for (int i = 1; i <= n; i++) {
    initialModified[i] = indirection[initial[i]];
  }
  int stillIncreasing = 1;
  for (int i = 2; i <= n; i++) {
    if (initialModified[i] < initialModified[i - 1]) {
      cout << n - i + 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}
