#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, min, h, cnt = 0;
  cin >> n;
  vector<long long> a, b;
  vector<pair<long long, long long> > v;
  pair<long long, long long> q;
  for (int i = 0; i < n; i++) {
    a.push_back(0);
    b.push_back(0);
  }
  for (int i = 0; i < n; i++) {
    cin >> h;
    a[h - 1] = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> h;
    b[h - 1] = i;
  }
  for (int i = 0; i < n; i++) {
    q.first = a[i];
    q.second = b[i];
    v.push_back(q);
  }
  sort(v.begin(), v.end());
  min = v[0].second;
  for (int i = 1; i < n; i++) {
    if (min > v[i].second) {
      cnt++;
    }
    min = max(min, v[i].second);
  }
  cout << cnt;
}
