#include <bits/stdc++.h>
using namespace std;
int n, a[1000010], p[1000010], tree[4000000];
void update(int v, int l, int r, int pos, int value) {
  if (l == r && l == pos)
    tree[v] = value;
  else {
    int mid = (l + r) / 2;
    if (pos <= mid)
      update(2 * v, l, mid, pos, value);
    else
      update(2 * v + 1, mid + 1, r, pos, value);
    tree[v] = max(tree[2 * v], tree[2 * v + 1]);
  };
};
int search(int v, int l, int r, int L, int R) {
  if (L > R) return 0;
  if (l == L && r == R) return tree[v];
  int mid = (l + r) / 2;
  if (R <= mid) return search(2 * v, l, mid, L, R);
  if (L > mid) return search(2 * v + 1, mid + 1, r, L, R);
  return max(search(2 * v, l, mid, L, mid),
             search(2 * v + 1, mid + 1, r, mid + 1, R));
};
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int v;
    scanf("%d", &v);
    a[v] = i;
  };
  for (int i = 1; i <= n; i++) {
    int v;
    scanf("%d", &v);
    p[i] = a[v];
  };
  for (int i = 1; i <= n; i++)
    update(1, 1, n, p[i], search(1, 1, n, p[i] + 1, n) + 1);
  printf("%d\n", tree[1]);
  return 0;
}
