#include <bits/stdc++.h>
using namespace std;
const int maxn = 1111111;
int a[maxn], b[maxn];
int c[maxn], d[maxn];
int st[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    c[a[i]] = n - i;
  }
  int m = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    d[i] = c[b[i]];
    int lo = 0, hi = m - 1;
    while (lo <= hi) {
      int mid = (lo + hi) >> 1;
      if (st[mid] < d[i])
        lo = mid + 1;
      else
        hi = mid - 1;
    }
    st[lo] = d[i];
    if (lo == m) m++;
  }
  printf("%d\n", m);
  return 0;
}
