#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  unordered_map<int, int> ourmap;
  int* first = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> first[i];
  }
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    ourmap[temp] = i + 1;
  }
  for (int i = 0; i < n; i++) {
    first[i] = ourmap[first[i]];
  }
  int ans = 1;
  for (int i = 0; i < n - 1; i++) {
    if (first[i] < first[i + 1])
      ans++;
    else
      break;
  }
  ans = n - ans;
  cout << ans;
  return 0;
}
