#include <bits/stdc++.h>
using namespace std;
queue<int> q;
bool mrk[100010];
int main() {
  int n, a;
  int ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    q.push(a);
  }
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (q.empty() == true) continue;
    if (a == q.front()) {
      q.pop();
    } else if (a != q.front() && mrk[q.front()] == 0) {
      mrk[a] = 1;
      ans++;
    } else {
      while (1) {
        if (q.empty() == true)
          break;
        else if (mrk[q.front()] == 1)
          q.pop();
        else if (q.front() == a) {
          q.pop();
          break;
        } else if (a != q.front() && mrk[q.front()] == 0) {
          ans++;
          mrk[a] = 1;
          break;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
