#include <bits/stdc++.h>
using namespace std;
bool was[200005];
int s[200005];
int t[200005];
int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> t[i];
  }
  int l = n - 1, r = n - 1;
  while (r > 0) {
    if (t[r] == s[l]) {
      --r;
      --l;
    } else if (was[t[r]]) {
      --r;
    } else {
      ans = n - l;
      was[s[l]] = true;
      --l;
    }
  }
  cout << ans << endl;
  return 0;
}
