#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn], b[maxn], ft[maxn], n;
map<int, int> m;
int last(int x) { return x & (-x); }
void upd(int j) {
  for (; j < maxn; j += last(j)) ft[j] += 1;
}
int qry(int j) {
  int sum = 0;
  for (; j; j -= last(j)) sum += ft[j];
  return sum;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[i] = i + 1;
    m[x] = a[i];
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    b[i] = m[x];
  }
  int ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    ans += (bool)qry(b[i]);
    upd(b[i]);
  }
  cout << ans << '\n';
  return 0;
}
