#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t = 0, x = 0;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    cin >> x;
    t += (x == a[t]);
  }
  cout << n - t;
}
