#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 15;
const int maxm = 1e6 + 15;
const int inf = 0x3f3f3f3f;
int a[maxn], b[maxn];
int main() {
  int n, x;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &x), a[x] = i;
  for (int i = 1; i <= n; i++) scanf("%d", &x), b[i] = -a[x];
  memset(a, 0, sizeof a);
  for (int i = 1; i <= n; i++) *lower_bound(a + 1, a + 1 + n, b[i]) = b[i];
  cout << lower_bound(a + 1, a + 1 + n, 0) - a - 1 << endl;
  return 0;
}
