#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
void fill_(S& buf, const T& x) {
  fill_n(reinterpret_cast<T*>(&buf), sizeof(buf) / sizeof(T), x);
}
template <typename T, int N>
inline int countof(const T (&)[N]) {
  return N;
}
template <typename T>
inline vector<T>& operator+=(vector<T>& ret, const T& x) {
  ret.push_back(x);
  return ret;
}
int N;
void solve(vector<int>& ret, const vector<int>& as, const vector<int>& bs) {
  ret.clear();
  const int INF = INT_MAX;
  const int N = int((as).size()), M = int((bs).size());
  vector<int> table(N + 1);
  for (int j = M - 1; j >= 0; --j) table[bs[j]] = j;
  vector<int> xs(N + 1, INF);
  vector<pair<int, int> > buf(N + 1, make_pair(-1, -1));
  xs[0] = -INF;
  for (int i = int(0), CNT_i = int(N); i < CNT_i; ++i) {
    int y = table[as[i]];
    int k = lower_bound((xs).begin(), (xs).end(), y) - xs.begin();
    xs[k] = y;
    buf[k] = make_pair(bs[y], k - 1);
  }
  for (int i = find((xs).begin(), (xs).end(), INF) - xs.begin() - 1;
       buf[i].second >= 0; i = buf[i].second)
    ret += buf[i].first;
  reverse((ret).begin(), (ret).end());
}
int main(int argc, char* argv[]) {
  while (cin >> N) {
    vector<int> as(N), bs(N);
    for (int i = int(0), CNT_i = int(N); i < CNT_i; ++i) cin >> as[i];
    for (int i = int(0), CNT_i = int(N); i < CNT_i; ++i) cin >> bs[i];
    reverse((bs).begin(), (bs).end());
    vector<int> ret;
    solve(ret, as, bs);
    cout << int((ret).size()) << endl;
  }
  return 0;
}
