#include <bits/stdc++.h>
using namespace std;
const int M = 1000000 + 5;
int remapped[M];
int ihash[M];
int LDS[M];
int len[M];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    ihash[x] = i;
  }
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    remapped[i] = ihash[x];
  }
  LDS[1] = 1;
  len[1] = remapped[1];
  for (int i = 2; i <= n; i++) {
    int I_L = 1;
    int I_R = i - 1;
    while (I_L < I_R) {
      int I_M = (I_L + I_R + 1) / 2;
      if (len[I_M] > remapped[i]) {
        I_L = I_M;
      } else {
        I_R = I_M - 1;
      }
    }
    if (len[I_L] > remapped[i]) {
      LDS[i] = I_L + 1;
      len[I_L + 1] = remapped[i];
    } else {
      LDS[i] = 1;
      len[1] = remapped[i];
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (LDS[i] > ans) {
      ans = LDS[i];
    }
  }
  cout << ans << endl;
  return 0;
}
