#include <bits/stdc++.h>
using namespace std;
ifstream fin("in.in");
ofstream fout("out.out");
const int N = 1000000 + 10;
int n, id[N], a[N];
vector<int> BIS;
inline void LIS() {
  BIS.push_back(a[1]);
  for (int i = 2; i <= n; i++) {
    int lb = lower_bound(BIS.begin(), BIS.end(), a[i]) - BIS.begin();
    if (lb == BIS.size())
      BIS.push_back(a[i]);
    else
      BIS[lb] = a[i];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = n; i; i--) {
    int x;
    cin >> x;
    id[x] = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] = id[a[i]];
  }
  LIS();
  cout << BIS.size();
  return 0;
}
