#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> datos(n + 5);
  vector<int> orden;
  vector<int> LDS, pre;
  for (int i = 0; i < (int)(n); i++) {
    int aux;
    scanf("%d", &aux);
    ;
    datos[aux] = i + 1;
  }
  for (int i = 0; i < (int)(n); i++) {
    int aux;
    scanf("%d", &aux);
    ;
    orden.push_back(datos[aux]);
  }
  for (int i = 0; i < (int)(n + 5); i++) {
    LDS.push_back(0);
    pre.push_back(0);
  }
  int maxi = 0, longi = 0;
  for (int i = 0; i < (int)(n); i++) {
    int auxi = orden[i];
    int left = 1, right = longi;
    while (left <= right) {
      int mid = (left + right) / 2;
      if (pre[mid] > auxi)
        left = mid + 1;
      else
        right = mid - 1;
    }
    LDS[i] = left;
    pre[left] = auxi;
    if (left > longi) longi = left;
    if (LDS[i] > maxi) maxi = LDS[i];
  }
  printf("%d\n", maxi);
  return 0;
}
