#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> in(n);
  for (int i = 0; i < n; i++) cin >> in[i];
  reverse(in.begin(), in.end());
  vector<int> out(n);
  for (int i = 0; i < n; i++) cin >> out[i];
  reverse(out.begin(), out.end());
  stack<int> s1, s2;
  for (int i = 0; i < n; i++) {
    s1.push(in[i]);
    s2.push(out[i]);
  }
  bool fined[n + 1];
  memset(fined, 0, sizeof(fined));
  while (!s1.empty() && !s2.empty()) {
    if (!fined[s1.top()] && s1.top() != s2.top()) {
      fined[s2.top()] = true;
      s2.pop();
    } else if (fined[s1.top()] && s1.top() != s2.top()) {
      s1.pop();
    } else if (s1.top() == s2.top()) {
      s1.pop();
      s2.pop();
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (fined[i]) ans++;
  cout << ans << endl;
}
