#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int ar[n], i;
  map<long long int, long long int> mp;
  for (i = 0; i < n; i++) {
    cin >> ar[i];
    mp[ar[i]] = i;
  }
  long long int count = 0;
  long long int br[n], j;
  for (i = 0; i < n; i++) cin >> br[i];
  i = 0, j = 0;
  while (i < n && j < n) {
    if (mp[ar[i]] == -1) {
      i++;
    } else if (ar[i] == br[j]) {
      mp[ar[i]] = -1;
      i++;
      j++;
    } else if (ar[i] != br[j]) {
      count++;
      mp[br[j]] = -1;
      j++;
    }
  }
  cout << count << endl;
}
