#include <bits/stdc++.h>
using namespace std;
class BinaryIndexedTree {
  int N;
  vector<int> tree;

 public:
  BinaryIndexedTree(int _N) : N(_N), tree(_N + 1) {}
  int query(int idx) {
    int res = 0;
    for (int i = idx; i > 0; i -= (i & -i)) res = max(res, tree[i]);
    return res;
  }
  void update(int idx, int val = 1) {
    for (int i = idx; i <= N; i += (i & -i)) tree[i] = max(tree[i], val);
  }
};
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> ray_in(N + 1);
  for (int i = (1), _b = (N); i <= _b; ++i) cin >> ray_in[i];
  vector<int> out_hole(N + 1);
  for (int i = (1), _b = (N); i <= _b; ++i) {
    int x;
    cin >> x;
    out_hole[x] = i;
  }
  int res = 0;
  BinaryIndexedTree bit(N);
  for (int i = N; i >= 1; --i) {
    int x = ray_in[i];
    int max_group_size = bit.query(out_hole[x]);
    res = max(res, max_group_size + 1);
    bit.update(out_hole[x], max_group_size + 1);
  }
  cout << res << endl;
  return 0;
}
