#include <bits/stdc++.h>
const int BIG = 1e6 + 55;
const int BIGG = 1e9 + 7;
const long long BIGGE = 1e12 + 55;
const double SML = (1e-7);
using namespace std;
int n, pos[BIG], arr[BIG];
set<int> s;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    pos[a - 1] = n - i - 1;
  }
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    arr[i] = pos[a - 1];
  }
  for (int i = 0; i < n; i++) {
    int x = arr[i];
    auto it = s.lower_bound(x);
    if (it != s.end()) s.erase(it);
    s.insert(x);
  }
  cout << s.size();
  return 0;
}
