#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265359;
int main() {
  vector<int> v;
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long j = 0, i = 0, f = 0, n, x = -1, t = 0, g = 0, r, qr, qc, z = 100;
  ;
  cin >> n;
  long long a[n], b[n], c[n], d[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    c[a[i]] = i;
  }
  for (i = 0; i < n; i++) {
    cin >> b[i];
    d[b[i]] = i;
  }
  int k = -1, ans = n;
  for (i = 0; i < n; i++) {
    if (d[a[i]] > k) {
      ans--;
      k = d[a[i]];
    } else
      break;
  }
  cout << ans << endl;
  return 0;
}
