#include <bits/stdc++.h>
using namespace std;
int n, a, b[200004], ans, mark, c[200004], p;
int main() {
  int i, j;
  cin >> n;
  for (i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (i = 1; i <= n; i++) {
    scanf("%d", &a);
    b[a] = i;
  }
  for (i = 1; i <= n; i++) {
    p = c[i];
    if (b[p] > mark) {
      mark = b[p];
      ans++;
    } else
      break;
  }
  cout << n - ans;
  return 0;
}
