#include <bits/stdc++.h>
using namespace std;
void file() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
void fast() {
  ios::sync_with_stdio(0);
  cin.tie(0);
}
int main() {
  int n;
  cin >> n;
  int x[n], y[n], ind[n + 5];
  for (int i = 0; i < n; i++) cin >> x[i], ind[x[i]] = i;
  for (int i = 0; i < n; i++) cin >> y[i];
  int s = 0, j = 0;
  for (int i = 0; i < n; i++) {
    if (x[i - j] != y[i]) s += (n - ind[y[i]] - j), j++;
  }
  cout << s << endl;
  return 0;
}
