#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
long long int int_pow(long long int base, long long int exp) {
  long long int result = 1;
  while (exp) {
    if (exp & 1) result *= base;
    exp /= 2;
    base *= base;
  }
  return result;
}
long long int mark[MAXN], last[MAXN], d[MAXN];
vector<pair<long long int, long long int> > v;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, a, ans = 0;
  cin >> n;
  for (long long int i = 0; i < n; i++) cin >> a, mark[a] = i + 1;
  for (long long int i = 0; i < n; i++) cin >> a, v.push_back({mark[a], i + 1});
  sort(v.begin(), v.end());
  memset(last, INF, sizeof last);
  last[0] = 0;
  for (long long int i = 0; i < n; i++) {
    long long int p = lower_bound(last, last + n, v[n - i - 1].second) - last;
    d[i] = p;
    last[p] = min(last[p], v[n - i - 1].second);
    ans = max(ans, d[i]);
  }
  cout << ans;
}
