#include <bits/stdc++.h>
using namespace std;
const int inf = 100000000;
int bin_search(int *a, int L, int R, int val) {
  int M;
  while (R - L > 1) {
    M = (L + R) / 2;
    if (a[M] > val)
      R = M;
    else
      L = M;
  }
  if (a[R] < val)
    return R;
  else
    return L;
}
int solve(int *a, int n) {
  int *dp = new int[n + 1];
  dp[0] = -inf;
  for (int i = 1; i <= n; i++) dp[i] = inf;
  for (int i = 1; i <= n; i++) {
    int temp = bin_search(dp, 0, n - 1, a[i]);
    dp[temp + 1] = a[i];
  }
  int temp = 0;
  for (int i = 1; i <= n; i++) {
    if (dp[i] != inf) temp = i;
  }
  delete[] dp;
  return temp;
}
int main() {
  int n;
  int *a, *y;
  cin >> n;
  int temp;
  a = new int[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> temp;
    a[temp] = i;
  }
  y = new int[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> temp;
    y[i] = a[temp];
  }
  for (int i = 1, j = n; i < j; i++, j--) swap(y[i], y[j]);
  cout << solve(y, n);
  delete[] a;
  delete[] y;
  return 0;
}
