#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = double;
const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 1010;
const int MAXK = 110;
const int MAXQ = 200010;
int n, a[MAXN], b[MAXN], f[MAXN], t[MAXN];
void update(int u, int gt) {
  while (u) {
    t[u] += gt;
    u = u - (u & (-u));
  }
}
int get(int u) {
  int res = 0;
  while (u <= 100000) {
    res += t[u];
    u = u + (u & (-u));
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cin >> n;
  for (int i = (1); i <= (n); i++) cin >> a[i];
  for (int i = (1); i <= (n); i++) {
    cin >> b[i];
    f[b[i]] = i;
  }
  for (int i = (1); i <= (n); i++) update(i, 1);
  int res = 0;
  for (int i = (n); i >= (1); i--) {
    int g = a[i];
    int pos = f[g];
    if (get(pos + 1)) res++;
    update(pos, -1);
  }
  cout << res;
  return 0;
}
