#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
const long long int mod = 1e9 + 7;
const long long int inf = 1e16;
int a[N], b[N], p[N], dp[N];
int main() {
  ios_base::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 = 0; i < n; i++) {
    int x;
    cin >> x;
    b[x] = i;
  }
  for (int i = 0; i < n; i++) {
    p[i] = b[a[i]];
  }
  reverse(p, p + n);
  int l = 0;
  for (int i = 0; i < n; i++) {
    int pt = lower_bound(dp, dp + l, p[i]) - dp;
    dp[pt] = p[i];
    l = max(l, pt + 1);
  }
  cout << l << endl;
  return 0;
}
