#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int arr[n];
  int x;
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    arr[x - 1] = i;
  }
  int vv[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    vv[i] = arr[x - 1];
  }
  int dp[1000001];
  for (int i = 0; i < 1000001; i++) dp[i] = 1e9;
  int mx = 0;
  for (int i = n - 1; i >= 0; i--) {
    int it = upper_bound(dp, dp + 1000001, vv[i]) - dp;
    dp[it] = vv[i];
    mx = max(mx, it + 1);
  }
  printf("%d", mx);
  return 0;
}
