#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  int cur = 0;
  for (int i = 0; i < n; ++i) {
    if (b[i] == a[cur]) ++cur;
  }
  cout << n - cur << endl;
  return 0;
}
