#include <bits/stdc++.h>
using namespace std;
const int maxN = 1000100;
int pos[maxN], p[maxN], n, lis[maxN], maxL;
int calc_lis() {
  lis[maxL] = INT_MAX;
  for (int i = 0; i < (n); ++i) {
    int lo = 0, hi = maxL, mid;
    while (lo < hi) {
      mid = (lo + hi + 1) / 2;
      if (lis[mid] > p[i])
        lo = mid;
      else
        hi = mid - 1;
    }
    if (lo == maxL)
      lis[++maxL] = p[i];
    else
      lis[lo + 1] = max(lis[lo + 1], p[i]);
  }
  return maxL;
}
int main() {
  int x;
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    cin >> x;
    pos[x] = i;
  }
  for (int i = 0; i < (n); ++i) {
    cin >> x;
    p[i] = pos[x];
  }
  cout << calc_lis() << endl;
  return 0;
}
