#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;
int temp[10000005], xs[10000005], dp[10000005];
int solve() {
  const int inf = INT_MAX;
  int best = 1;
  fill_(dp, inf);
  for (int i = int(0), CNT_i = int(N); i < CNT_i; ++i) {
    int idx = lower_bound(dp, dp + best, xs[i]) - dp;
    best = max(best, idx + 1);
    dp[idx] = xs[i];
  }
  return best;
}
int main(int argc, char* argv[]) {
  int x;
  while (scanf("%d", &N) == 1) {
    for (int i = int(0), CNT_i = int(N); i < CNT_i; ++i)
      scanf("%d", &x), temp[x] = i;
    for (int i = int(N) - 1; i >= 0; --i) scanf("%d", &x), xs[i] = temp[x];
    printf("%d\n", solve());
  }
  return 0;
}
