#include <bits/stdc++.h>
using namespace std;
int n, num[1000005], num2[1000005], dp[1000005];
int get(int l, int r, int v) {
  if (dp[0] < v) return -1;
  int lo = l, hi = r, res = 0;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (dp[mid] >= v)
      lo = mid + 1, res = max(res, mid);
    else
      hi = mid - 1;
  }
  return res;
}
int main() {
  int a;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    num[a] = i;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    num2[i] = num[a];
  }
  int tmp = 0;
  dp[tmp++] = num2[1];
  for (int i = 2; i <= n; i++) {
    if (num2[i] < dp[tmp - 1])
      dp[tmp++] = num2[i];
    else {
      int tt = get(0, tmp - 1, num2[i]);
      dp[tt + 1] = num2[i];
    }
  }
  printf("%d\n", tmp);
  return 0;
}
