#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n;
  cin >> n;
  deque<long long int> enter;
  deque<long long int> exit;
  for (auto i = 0; i < n; i++) {
    long long int t;
    cin >> t;
    enter.push_back(t);
  }
  for (auto i = 0; i < n; i++) {
    long long int t;
    cin >> t;
    exit.push_back(t);
  }
  vector<bool> visited(n + 1, false);
  long long int ans = 0;
  while (exit.empty() == false) {
    long long int no = exit.front();
    exit.pop_front();
    while (visited[enter.front()] == true) enter.pop_front();
    if (no == enter.front()) {
      visited[no] = true;
      enter.pop_front();
    } else {
      ans++;
      visited[no] = true;
    }
  }
  cout << ans << endl;
}
int main(int argc, const char* argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int tests = 1;
  while (tests--) {
    solve();
  }
  return 0;
}
