#include <bits/stdc++.h>
using namespace std;
const double eps = 1E-9;
const int INF = 1000 * 1000 * 1000;
int n;
int x[1000010];
int to[1000010];
int y[1000010];
int f[1000010];
int ans = 0;
int getmax(int r) {
  int result = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) result = max(result, f[r]);
  return result;
}
void update(int i, int new_val) {
  for (; i < n; i = (i | (i + 1))) f[i] = max(f[i], new_val);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &x[i]);
  for (int i = 0; i < n; i++) {
    scanf("%d", &y[i]);
    to[y[i]] = i;
  }
  for (int i = n - 1; i >= 0; i--) {
    int cur = getmax(to[x[i]] - 1) + 1;
    ans = max(ans, cur);
    update(to[x[i]], cur);
  }
  printf("%d\n", ans);
  return 0;
}
