#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  int arr[t + 5], ar2[t + 5], expos[t + 5], flag = 0, max = 0;
  for (int i = 1; i <= t; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= t; i++) {
    cin >> ar2[i];
    expos[ar2[i]] = i;
  }
  for (int i = 1; i <= t; i++) {
    if (expos[arr[i]] > max) {
      max = expos[arr[i]];
    } else
      flag++;
  }
  cout << flag << "\n";
  return 0;
}
