#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int a[N], b[N], c[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.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;
    c[x] = i;
  }
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    v[i] = c[a[i]];
  }
  reverse(v.begin(), v.end());
  vector<int> lds;
  for (int i = 0; i < n; i++) {
    if (lds.empty() || lds.back() < v[i]) {
      lds.push_back(v[i]);
      continue;
    }
    int pos = lower_bound(lds.begin(), lds.end(), v[i]) - lds.begin();
    lds[pos] = v[i];
  }
  cout << lds.size();
  return 0;
}
