#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 1;
const double eps = 1e-15;
const int pw = 257;
int n, a[N], b, t[N * 4], pos[N];
int get(int v, int l, int r, int L, int R) {
  if (L > R || r < L || R < l) return 0;
  if (L <= l && r <= R) return t[v];
  int mid = (l + r) >> 1;
  return max(get(v + v, l, mid, L, R), get(v + v + 1, mid + 1, r, L, R));
}
void upd(int v, int l, int r, int pos, int val) {
  if (l == r) {
    t[v] = val;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    upd(v + v, l, mid, pos, val);
  else
    upd(v + v + 1, mid + 1, r, pos, val);
  t[v] = max(t[v + v], t[v + v + 1]);
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    pos[a[i]] = i;
  }
  for (int i = 1; i <= n; ++i) {
    cin >> b;
    a[pos[b]] = i;
  }
  for (int i = 1; i <= n; ++i)
    upd(1, 1, n, a[i], get(1, 1, n, a[i] + 1, n) + 1);
  cout << get(1, 1, n, 1, n);
  return 0;
}
