#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  int p = 0;
  int t = 0;
  bool test = false;
  while (t < n) {
    test = false;
    while (p < n && a[t] != b[p]) {
      p++;
    }
    if (p < n) {
      test = true;
    }
    if (test == false) {
      break;
    } else {
      t++;
    }
  }
  cout << n - t << endl;
  return 0;
}
