#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5 + 10;
int main() {
  std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  map<int, bool> mark;
  stack<int> st;
  int in;
  int arr[nmax];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = n - 1; i >= 0; i--) {
    st.push(arr[i]);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    while (mark[st.top()]) st.pop();
    cin >> in;
    if (st.top() != in) {
      mark[in] = 1;
      ans++;
      continue;
    }
    if (st.top() == in) {
      st.pop();
      continue;
    }
  }
  cout << ans << endl;
  return 0;
}
