#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  queue<int> q;
  vector<char> ch(n + 1);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    q.push(temp);
  }
  int now = q.front();
  q.pop();
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    if (temp == now) {
      while (!q.empty()) {
        now = q.front();
        q.pop();
        if (!ch[now]) break;
      }
    } else {
      if (!ch[temp]) {
        ans++;
        ch[temp] = true;
      }
    }
  }
  cout << ans;
}
