#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2 * (100000) + 5;
int a[MAXN], b[MAXN];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  int res = 0;
  int j = 0;
  for (int i = 0; i < n && j < n; ++i) {
    while (j < n && a[i] != b[j]) {
      j++;
      res++;
    }
    j++;
  }
  cout << res << endl;
  return 0;
}
