#include <bits/stdc++.h>
using namespace std;
int n, ans;
vector<int> p, p1;
bool visited[2 * 100001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n;
  p.resize(n);
  p1.resize(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  for (int i = 0; i < n; i++) cin >> p1[i];
  int i = 0, j = 0;
  while (i < p.size() && j < p1.size()) {
    if (p[i] == p1[j])
      i++, j++;
    else if (visited[p1[j]])
      j++;
    else {
      while (p1[j] != p.back()) {
        visited[p.back()] = 1;
        ans++;
        p.pop_back();
      }
      p.pop_back();
      ans++;
      j++;
    }
  }
  cout << ans << endl;
  return 0;
}
