#include <bits/stdc++.h>
using namespace std;
const int _ = 4e5 + 7;
long long read() {
  long long x;
  cin >> x;
  return x;
}
int n, a[_], b[_], hav[_], dsr[_], vis[_];
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1; i <= n; ++i) b[i] = read(), hav[b[i]] = i;
  int js = 0, p = 1, ans = 0;
  for (int i = 1; i <= n; ++i) {
    vis[a[i]] = 1;
    if (p > hav[a[i]]) {
      ans++;
      js++;
    } else {
      while (p <= hav[a[i]]) js += vis[b[p]], p++;
      if (js < i) ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}
