#include <bits/stdc++.h>
using namespace std;
const int oo = 1 << 29;
int a[1000010], b[1000010];
int id[1000010];
int dp[1000010];
int len;
int n;
int find(int val) {
  int l = 0, r = len;
  while (l + 1 < r) {
    int mid = (l + r) >> 1;
    if (dp[mid] <= val) {
      r = mid;
    } else
      l = mid;
  }
  return r;
}
int sol() {
  for (int i = 0; i < n; ++i) id[a[i]] = i;
  for (int i = 0; i < n; ++i) b[i] = id[b[i]];
  len = 0;
  dp[len++] = oo;
  for (int i = 0; i < n; ++i) {
    int pos = find(b[i]);
    if (pos < len) {
      dp[pos] = b[i];
    } else {
      dp[len++] = b[i];
    }
  }
  return len - 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < n; ++i) scanf("%d", &b[i]);
  printf("%d\n", sol());
}
