#include <bits/stdc++.h>
using namespace std;
int N, S[1000005], P[1000005], B[1000005], ans, X[1000005], L, t;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &S[i]);
    P[S[i]] = i;
  }
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &B[i]);
    B[i] = P[B[i]];
  }
  reverse(B + 1, B + N + 1);
  for (int i = 1; i <= N; ++i) {
    t = lower_bound(X, X + L, B[i]) - X;
    X[t] = B[i];
    L = max(L, t + 1);
  }
  printf("%d\n", L);
}
