#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n;
  cin >> n;
  queue<int> q;
  int x;
  vector<int> exit;
  for (int i = 0; i < n; i++) {
    cin >> x;
    q.push(x);
  }
  for (int i = 0; i < n; i++) {
    cin >> x;
    exit.push_back(x);
  }
  bool visited[n + 1];
  memset(visited, false, sizeof(visited));
  int ans = 0, i = 0;
  while (!q.empty() && i < n) {
    if (visited[q.front()] == false) {
      if (q.front() == exit[i]) {
        visited[q.front()] = true;
        i++;
        q.pop();
      } else {
        visited[exit[i]] = true;
        ans++;
        i++;
      }
    } else
      q.pop();
  }
  cout << ans << endl;
  return 0;
}
