#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int s1[n];
  int s2[n];
  for (int i = 0; i < n; i++) cin >> s1[i];
  for (int i = 0; i < n; i++) cin >> s2[i];
  for (int i = 0; i < n; i++) s1[i]--, s2[i]--;
  int arr[n];
  for (int i = 0; i < n; i++) {
    arr[s2[i]] = i;
  }
  for (int i = 0; i < n - 1; i++) {
    if (arr[s1[i]] > arr[s1[i + 1]]) {
      cout << n - 1 - i << "\n";
      return 0;
    }
  }
  cout << "0\n";
  return 0;
}
