#include <bits/stdc++.h>
using namespace std;
int n, arr1[200005], arr2[200005], num;
int main() {
  ios_base::sync_with_stdio(), cin.tie(nullptr), cout.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> arr1[i];
  for (int i = 0; i < n; ++i) cin >> num, arr2[num] = i;
  for (int i = 0; i < n; ++i) arr1[i] = arr2[arr1[i]];
  int i = 0;
  for (; i < n; ++i) {
    if (i && arr1[i] < arr1[i - 1]) break;
  }
  cout << n - i << endl;
}
