#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, a[N], b[N], pos[N], t[N], ans;
int get(int pos) {
  int cur = 0;
  for (; pos >= 0; pos &= pos + 1, pos--) {
    cur = max(cur, t[pos]);
  }
  return cur;
}
void update(int pos, int val) {
  for (; pos <= n; pos |= pos + 1) {
    t[pos] = max(t[pos], val);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
    pos[b[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    b[i] = pos[a[i]];
  }
  for (int i = n; i >= 1; i--) {
    int cur = get(b[i] - 1) + 1;
    ans = max(ans, cur);
    update(b[i], cur);
  }
  cout << ans;
}
