#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int i, j = 1, k = 1, ans = 0;
  int N;
  cin >> N;
  map<int, int> m;
  map<int, int> n;
  int A[N], B[N];
  for (i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (i = 0; i < N; i++) {
    cin >> B[i];
    m[B[i]] = i;
  }
  int high;
  high = m[A[0]];
  for (i = 1; i < N; i++) {
    if (m[A[i]] > high) high = m[A[i]];
    if (m[A[i]] < high) ans++;
  }
  cout << ans << endl;
}
