#include <bits/stdc++.h>
using namespace std;
struct Line {
  int x, y;
  bool operator<(const Line &p) const { return y > p.y; }
} p[1000010];
int n;
int stk[1000010], top;
void init() {
  scanf("%d", &n);
  for (int x, i = 1; i <= n; ++i) scanf("%d", &x), p[x].x = i;
  for (int x, i = 1; i <= n; ++i) scanf("%d", &x), p[x].y = i;
}
void solve() {
  sort(p + 1, p + n + 1);
  top = 0;
  for (int l, r, mid, i = 1; i <= n; ++i) {
    if (top == 0 || stk[top - 1] < p[i].x)
      stk[top++] = p[i].x;
    else {
      for (l = 0, r = top - 1; l <= r;) {
        mid = (l + r) / 2;
        if (stk[mid] <= p[i].x)
          l = mid + 1;
        else {
          if (l == r) break;
          r = mid;
        }
      }
      stk[r] = p[i].x;
    }
  }
  printf("%d\n", top);
}
int main() {
  init();
  solve();
  return 0;
}
