#include <bits/stdc++.h>
using namespace std;
int s1[200010], s2[200010];
map<int, int> m;
int main() {
  int n, i;
  while (cin >> n) {
    for (i = 1; i <= n; i++) cin >> s1[i];
    for (i = 1; i <= n; i++) {
      cin >> s2[i];
      m[s2[i]] = i;
    }
    for (i = 1; i < n; i++) {
      if (m[s1[i]] > m[s1[i + 1]]) break;
    }
    cout << n - i << endl;
  }
  return 0;
}
