#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int arr1[N], arr2[N], ind[N];
int n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr1[i];
    ind[arr1[i]] = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> arr2[i];
  }
  int mn = n;
  int ans = 0;
  for (int i = n - 1; ~i; --i) {
    if (mn < ind[arr2[i]]) {
      ans++;
    } else {
      mn = ind[arr2[i]];
    }
  }
  cout << ans << endl;
}
