#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> vec;
  long long thn[100002];
  for (long long i = 0; i < n; i++) {
    long long num;
    cin >> num;
    vec.push_back(num);
  }
  for (long long i = 0; i < n; i++) {
    long long num;
    cin >> num;
    thn[num] = i + 1;
  }
  long long pos = 0, ans = 0;
  for (long long i = 0; i < n; i++) {
    long long p = vec[i];
    if (thn[p] > pos) {
      ans += (thn[p] - pos - 1);
      pos = thn[p];
    }
  }
  cout << ans << endl;
}
