#include <bits/stdc++.h>
int x[1000000], a[1000000], v[1000000];
int lis(int n) {
  int i, len, j, j1, j2;
  len = 0;
  for (i = (0); i < (n); i++) {
    j1 = 1;
    j2 = len;
    while (j1 <= j2) {
      j = (j1 + j2) >> 1;
      if (a[i] <= a[v[j]])
        j2 = j - 1;
      else
        j1 = j + 1;
    }
    if (j1 > len) ++len;
    v[j1] = i;
  }
  return len;
}
int main() {
  int i, j, n;
  scanf("%d", &n);
  for (i = (n - 1); i >= (0); i--) {
    scanf("%d", &j);
    x[j] = i;
  }
  for (i = (0); i < (n); i++) {
    scanf("%d", &j);
    a[i] = x[j];
  }
  printf("%d\n", lis(n));
  return 0;
}
