#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n + 1], b[n + 1], c[n + 1], pos[n + 1], m = 0, answer = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= n; i++) {
    pos[b[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    c[i] = pos[a[i]];
  }
  for (int i = 1; i <= n; i++) {
    if (c[i] > m) {
      m = c[i];
    } else {
      answer++;
    }
  }
  cout << answer;
  return 0;
}
