#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n, a[N], b[N], d[N], cnt, id[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), id[a[i]] = i;
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]), b[i] = id[b[i]];
  for (int i = n; i >= 1; i--) {
    if (b[i] > d[cnt])
      d[++cnt] = b[i];
    else
      d[lower_bound(d + 1, d + 1 + cnt, b[i]) - d] = b[i];
  }
  cout << cnt;
  return 0;
}
