#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int arr[n];
  {
    int temp[n + 1];
    for (int i = 0; i < n; ++i) {
      int z;
      cin >> z;
      temp[z] = i;
    }
    for (int i = 0; i < n; ++i) {
      int z;
      cin >> z;
      arr[temp[z]] = i;
    }
  }
  int ans = 0;
  vector<int> dp(n, 0);
  for (int i = 0; i < n; ++i) {
    int x = upper_bound(dp.begin(), dp.begin() + ans, arr[i], greater<int>()) -
            dp.begin();
    dp[x] = arr[i];
    ans = max(ans, x + 1);
  }
  cout << ans << "\n";
  return 0;
}
