#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int a[N], b[N];
bool rev[N];
int main() {
  int n;
  cin >> n;
  for (int i = int(0); i < int(n); i++) cin >> a[i];
  for (int i = int(0); i < int(n); i++) cin >> b[i];
  int resp = 1;
  memset(rev, false, sizeof(rev));
  int pos = n;
  int c = 0;
  int ai = 0;
  for (int i = int(0); i < int(n); i++)
    if (!rev[b[i]]) {
      if (a[ai] == b[i]) {
        ai++;
        continue;
      }
      do {
        pos--;
        c++;
        rev[a[pos]] = true;
      } while (a[pos] != b[i]);
    }
  cout << c << endl;
  return 0;
}
