#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int cnt = 0;
  int h[n + 1], en1[n], ex1[n], en[n], ex[n], nen[n];
  for (int i = 0; i < n; i++) {
    cin >> en1[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> ex1[i];
  }
  int j = 0;
  for (int i = n - 1; i >= 0; i--) {
    en[j] = en1[i];
    ex[j] = ex1[i];
    h[en[j]] = j;
    j++;
  }
  j = n - 1;
  int i = n - 1;
  while (i >= 0) {
    if (en[j] == 0) {
      j--;
      continue;
    }
    if (ex[i] == en[j]) {
      nen[i] = en[j];
      j--;
      i--;
      continue;
    } else {
      nen[i] = ex[i];
      en[h[ex[i]]] = 0;
      i--;
      cnt++;
    }
  }
  cout << cnt;
}
