#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:20000000")
using namespace std;
const int MAX = 1 << 20;
const int INF = 1 << 30;
int A[MAX], X[MAX], Y[MAX], dp[MAX], N;
int P[MAX];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &X[i]);
    P[X[i]] = i;
  }
  for (int i = 1; i <= N; ++i) scanf("%d", &Y[i]);
  for (int i = 1; i <= N; ++i) {
    A[i] = P[Y[i]];
  }
  reverse(A + 1, A + N + 1);
  dp[0] = -INF;
  fill(dp + 1, dp + N + 2, INF);
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    int lo = 0, hi = N + 1;
    int x = A[i];
    while (lo < hi) {
      int mid = (lo + hi) >> 1;
      if (dp[mid] > x)
        hi = mid;
      else
        lo = mid + 1;
    }
    dp[lo] = x;
    ans = max(lo, ans);
  }
  cout << ans << endl;
  return 0;
}
