#include <bits/stdc++.h>
using namespace std;
int n, a[211111], b[211111];
vector<int> latestpos[211111];
int store[211111];
int movesmade;
int lastpos;
int main() {
  scanf("%d", &n);
  for (int i = 0; i <= n; i++) {
    latestpos[i].clear();
    store[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    latestpos[a[i]].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  movesmade = 0, lastpos = n;
  for (int i = 0; i < n; i++) {
    if (a[i - movesmade] != b[i]) {
      int id = b[i];
      int len = latestpos[id].size();
      int cpos = latestpos[id][len - 1];
      if (store[id] > 0) {
        movesmade++;
      } else {
        latestpos[id].pop_back();
        for (int j = lastpos - 1; j >= cpos; j--) {
          store[a[j]]++;
        }
        lastpos = min(lastpos, cpos);
        if (store[id] > 0) {
          movesmade++;
        }
      }
    }
  }
  printf("%d\n", movesmade);
  return 0;
}
