#include <bits/stdc++.h>
using namespace std;
int a[1000005], b[1000005], kol[1000005], pric[1000005], dp[1000005];
int vl[4000005], vr[4000005], t[4000005];
;
void build(int v, int l, int r) {
  vl[v] = l;
  vr[v] = r;
  if (l == r) {
    t[v] = 0;
    return;
  }
  int mid = (l + r) / 2;
  build(v * 2 + 1, l, mid);
  build(v * 2 + 2, mid + 1, r);
  t[v] = max(t[v * 2 + 1], t[v * 2 + 2]);
}
int maxi(int v, int l, int r) {
  if (vr[v] < l || r < vl[v]) return 0;
  if (l <= vl[v] && vr[v] <= r) return t[v];
  int ql = maxi(v * 2 + 1, l, r);
  int qr = maxi(v * 2 + 2, l, r);
  return max(ql, qr);
}
void modif(int v, int p, int val) {
  if (vl[v] == vr[v]) {
    t[v] = val;
    return;
  }
  int mid = (vl[v] + vr[v]) / 2;
  if (p <= mid)
    modif(v * 2 + 1, p, val);
  else
    modif(v * 2 + 2, p, val);
  t[v] = max(t[v * 2 + 1], t[v * 2 + 2]);
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    kol[a[i]] = i;
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  int l = 0;
  for (int i = 0; i < n; i++) {
    pric[l] = kol[b[i]] + 1;
    l++;
  }
  build(0, 0, n - 1);
  reverse(pric, pric + n);
  for (int i = 0; i < n; i++) {
    int pp = maxi(0, 0, pric[i] - 1);
    dp[i] = max(dp[i], pp + 1);
    modif(0, pric[i], dp[i]);
  }
  cout << *max_element(dp, dp + n);
}
