#include <bits/stdc++.h>
using namespace std;
const long d3 = 1000;
const long d4 = 10000;
const long d5 = 100000;
const long d6 = 1000000;
const long d7 = 10000000;
const long d8 = 100000000;
const long d9 = 1000000000;
long n, a[2 * d5], b[2 * d5];
inline bool check(long k) {
  long cur = 0;
  long indB = 0;
  bool ok = true;
  for (int indA = 0; ((indA < n - k) && (ok)); indA++) {
    while ((a[indA] != b[indB]) && (indB < n)) {
      indB++;
    }
    if (indB == n) {
      ok = false;
    }
  }
  return ok;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int j = 0; j < n; j++) {
    cin >> b[j];
  }
  long down = 0, up = n, tmp;
  while (up - down > 1) {
    tmp = (up + down) / 2;
    if (check(tmp)) {
      up = tmp;
    } else {
      down = tmp;
    }
  }
  while (!check(down)) down++;
  cout << down;
  return 0;
}
