#include <bits/stdc++.h>
using namespace std;
using namespace std;
void find_lis(vector<int> &a, vector<int> &b) {
  vector<int> p(a.size());
  int u, v;
  if (a.empty()) return;
  b.push_back(0);
  for (size_t i = 1; i < a.size(); i++) {
    if (a[b.back()] < a[i]) {
      p[i] = b.back();
      b.push_back(i);
      continue;
    }
    for (u = 0, v = b.size() - 1; u < v;) {
      int c = (u + v) / 2;
      if (a[b[c]] < a[i])
        u = c + 1;
      else
        v = c;
    }
    if (a[i] < a[b[u]]) {
      if (u > 0) p[i] = b[u - 1];
      b[u] = i;
    }
  }
  for (u = b.size(), v = b.back(); u--; v = p[v]) b[u] = v;
}
int main() {
  int n;
  cin >> n;
  int a[n], b[n], c[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    c[a[i]] = i;
  }
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) a[c[b[i]]] = i + 1;
  int q = a[0], sor = 1;
  for (int i = 1; a[i] > q && i < n; i++) {
    q = a[i];
    sor++;
  }
  cout << n - sor << endl;
  return 0;
}
