#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int *a1 = new int[n + 5];
  int *a2 = new int[n + 5];
  for (int i = 1; i <= n; i++) cin >> a1[i];
  int *pos = new int[n + 5];
  for (int i = 1; i <= n; i++) {
    cin >> a2[i];
    pos[a2[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    a1[i] = pos[a1[i]];
  }
  int cnt = 1;
  for (int i = 1; i <= n - 1; i++) {
    if (a1[i] <= a1[i + 1]) {
      cnt++;
    } else
      break;
  }
  cout << n - cnt << "\n";
  return 0;
}
