#include <bits/stdc++.h>
using namespace std;
int arr1[1000000], arr2[1000000];
map<int, int> mp;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr1[i];
  for (int i = 0; i < n; i++) {
    cin >> arr2[i];
    mp[arr2[i]] = i;
  }
  for (int i = 0; i < n; i++) arr1[i] = mp[arr1[i]];
  int coun = 1;
  for (int i = 1; i < n; i++) {
    if (arr1[i] >= arr1[i - 1])
      coun++;
    else
      break;
  }
  cout << n - coun;
  return 0;
}
