#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
int a[maxn], b[maxn], c[maxn], f[maxn];
int n;
int main() {
  scanf("%d", &n);
  int x;
  for (int i = 1; i <= n; ++i) scanf("%d", &x), c[x] = i;
  for (int i = 1; i <= n; ++i) scanf("%d", &x), b[x] = i;
  for (int i = 1; i <= n; ++i) a[c[i]] = b[i];
  reverse(a + 1, a + 1 + n);
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] > f[ans])
      f[++ans] = a[i];
    else if (a[i] < f[1])
      f[1] = a[i];
    else {
      int l = 1, r = ans;
      while (l <= r) {
        int mid = (l + r) >> 1;
        if (a[i] < f[mid])
          r = mid - 1;
        else
          l = mid + 1;
      }
      f[l] = a[i];
    }
  }
  printf("%d", ans);
  return 0;
}
