#include <bits/stdc++.h>
using namespace std;
int pos[1000001], x[1000011];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    pos[p] = i;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int p, b = 1;
    cin >> p;
    p = -pos[p];
    int lo = 1, hi = ans;
    int mi;
    while (lo <= hi) {
      mi = (lo + hi) / 2;
      if (x[mi] < p) {
        b = mi + 1;
        lo = mi + 1;
      } else {
        b = mi;
        hi = mi - 1;
      }
    }
    if (b == ans + 1) ans++;
    x[b] = p;
  }
  cout << ans << endl;
  return 0;
}
