#include <bits/stdc++.h>
using namespace std;
long long n, i, k, t, a[300009], b[300009];
int main() {
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) {
    cin >> k;
    b[k] = i;
  }
  for (i = 1; i <= n; i++) a[i] = b[a[i]];
  for (i = 1; i < n; i++)
    if (a[i] > a[i + 1]) break;
  cout << n - i;
}
