#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans = 0, p = 0;
  scanf("%d", &n);
  vector<bool> fined(n + 1);
  vector<int> a(n), b(n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
  for (int i = 0; i < n; ++i) {
    if (fined[a[i]] == false) {
      while (p < n and b[p] != a[i]) {
        ++ans;
        fined[b[p++]] = true;
      }
      ++p;
    }
  }
  printf("%d\n", ans);
}
