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