#include <bits/stdc++.h>
using namespace std;
int A[200001], B[200001];
int P[200001], WA[200001], WB[200001];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
    WA[A[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> B[i];
    WB[B[i]] = i;
  }
  for (int i = 1; i <= n; i++) P[WA[B[i]]] = i;
  int cnt = 1;
  for (int i = 2; i <= n; i++)
    if (P[i] > P[i - 1])
      cnt++;
    else
      break;
  cout << n - cnt << endl;
  return 0;
}
