#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  vector<int> p1;
  map<int, int> p2;
  vector<int>::iterator it;
  int n, i, temp, count;
  while (scanf("%d", &n) != EOF) {
    count = 0;
    p1.clear();
    p2.clear();
    for (i = 0; i < n; i++) {
      cin >> temp;
      p1.push_back(temp);
    }
    for (i = 0; i < n; i++) {
      cin >> temp;
      p2[temp] = i;
    }
    for (i = 1; i < n; i++) {
      if (p2[p1[i - 1]] > p2[p1[i]]) break;
    }
    cout << n - i << endl;
  }
  return 0;
}
