#include <bits/stdc++.h>
using namespace std;
int a[1010000], b[1010000], n, c[1010000];
int main() {
  int i, j, t, sum, u, k, l, r, mid, up;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  for (i = 0; i < n; i++) scanf("%d", &b[i]);
  for (i = 0; i < n; i++) c[b[i]] = i;
  for (i = 0; i < n; i++) a[i] = c[a[i]];
  for (i = 0; i < n; i++) c[i] = 0;
  c[0] = 100000000;
  up = 0;
  for (i = 0; i < n; i++) {
    l = 0, r = up;
    while (l <= r) {
      mid = (l + r) >> 1;
      if (c[mid] > a[i])
        l = mid + 1;
      else
        r = mid - 1;
    }
    if (l > up) up++;
    c[l] = a[i];
  }
  printf("%d\n", up);
  return 0;
}
