#include <bits/stdc++.h>
using namespace std;
int n;
int m = 0;
int a[1000000];
int b[1000000];
int c[1000000];
int p[1000000];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    --a[i];
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i]);
    --b[i];
    p[b[i]] = i;
  }
  for (int i = 0; i < n; ++i) c[i] = p[a[i]];
  for (int i = 0; i < n; ++i) {
    int low = 0;
    int high = m;
    while (low < high) {
      int mid = (low + high) / 2;
      if (p[mid] > c[i])
        low = mid + 1;
      else
        high = mid;
    }
    p[low] = c[i];
    if (low == m) ++m;
  }
  printf("%d\n", m);
  return 0;
}
