#include <bits/stdc++.h>
using namespace std;
int p1[200005], p2[200005];
int main() {
  int n, res = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p1[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> p2[i];
  }
  int count = 0;
  for (int i = 1; i <= n; i++) {
    if (p1[count + 1] == p2[i]) count++;
  }
  res = n - count;
  cout << res << endl;
  return 0;
}
