#include <bits/stdc++.h>
using namespace std;
int n, s1[1000005], r, s2[1000005], dp[1000005], w, mi, mid, ma;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s1[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &r);
    s2[r] = i;
  }
  for (int i = 1; i <= n; i++) {
    s1[i] = s2[s1[i]];
  }
  w = 0;
  dp[0] = 10000000;
  for (int i = 1; i <= n; i++) {
    if (dp[w] > s1[i]) {
      dp[++w] = s1[i];
    } else {
      mi = 0;
      ma = w;
      while (mi < ma) {
        mid = (mi + ma) >> 1;
        if (dp[mid] < s1[i]) {
          ma = mid;
        } else {
          mi = mid + 1;
        }
      }
      dp[mi] = s1[i];
    }
  }
  printf("%d\n", w);
  return 0;
}
