#include <bits/stdc++.h>
using namespace std;
long long a[400007], b[500006];
int main() {
  long long n, i, num;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) {
    cin >> num;
    b[num] = i;
  }
  for (i = 1; i <= n; i++)
    if (b[a[i]] > b[a[i + 1]]) {
      cout << n - i << endl;
      return 0;
    }
  cout << 0 << endl;
  return 0;
}
