#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int a[N], dp[N], dpp[N], pos[N], pa, push_back, p;
int n, k, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p;
    pos[p] = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> p;
    a[n - pos[p] + 1] = i;
    dpp[i] = 1e9;
  }
  for (int i = 1; i <= n; i++) {
    int x = upper_bound(dpp + 1, dpp + 1 + n, a[i]) - dpp;
    dpp[x] = a[i];
  }
  for (int i = n; i >= 1; i--) {
    if (dpp[i] != 1e9) {
      push_back = i;
      break;
    }
  }
  cout << push_back;
  return 0;
}
