#include <bits/stdc++.h>
using namespace std;
const int Inf = INT_MAX;
const double PI = 3.1415926535;
int n, a[200500], k;
map<int, int> m;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> k;
    m[k] = i;
  }
  for (long long i = 0; i < n; i++) {
    cin >> k;
    a[m[k]] = i + 1;
  }
  k = 0;
  for (long long i = 0; i < n; i++)
    if (a[i] > a[i + 1]) {
      k = i + 1;
      break;
    }
  cout << n - k;
  return 0;
}
