#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 50;
int a[maxn];
int c[maxn];
int dp[maxn];
int d[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = n - 1; i >= 0; i--) {
    int x;
    cin >> x;
    c[x] = i;
  }
  for (int i = 0; i < n; i++) {
    dp[i] = maxn;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int j = lower_bound(dp, dp + n, c[a[i]]) - dp;
    d[i] = j;
    dp[j] = c[a[i]];
    ans = max(ans, d[i]);
  }
  cout << ans + 1;
}
