#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:16000000")
#pragma warning(disable : 4996)
const int inf = 1 << 25;
const double eps = 1e-9;
const int INF = inf;
int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  vector<int> places(n);
  for (int i = (0); i < (n); ++i) {
    int xi;
    cin >> xi;
    --xi;
    places[xi] = n - i;
  }
  vector<int> a(n);
  for (int i = (0); i < (n); ++i) {
    int yi;
    cin >> yi;
    --yi;
    a[i] = places[yi];
  }
  vector<int> d(n + 1, INF);
  d[0] = -INF;
  vector<int> p(n);
  vector<int> no(n + 1);
  no[0] = -1;
  for (int i = 0; i < n; i++) {
    unsigned j = upper_bound(d.begin(), d.end(), a[i]) - d.begin() - 1;
    if (d[j] < a[i] && a[i] < d[j + 1]) {
      d[j + 1] = a[i];
      p[i] = no[j];
      no[j + 1] = i;
    }
  }
  int ans = 0;
  vector<int> result;
  for (int i = n; i >= 1; i--)
    if (d[i] != INF) {
      for (int cur = no[i]; cur != -1; cur = p[cur]) ++ans;
      break;
    }
  cout << ans << endl;
  return 0;
}
