#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000030;
int num[MAXN];
int a[MAXN], b[MAXN];
int dex[MAXN];
int res[MAXN];
int bsch(int le, int ri, int key) {
  int l = le, r = ri;
  while (l <= r) {
    int m = (l + r) / 2;
    if (res[m] == key)
      return m;
    else if (res[m] > key)
      r = m - 1;
    else
      l = m + 1;
  }
  return l;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &b[i]);
    dex[b[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    num[i] = dex[a[i]];
  }
  for (int i = 1; i <= n / 2; i++) {
    swap(num[i], num[n - i + 1]);
  }
  for (int i = 1; i <= n; i++) {
    res[i] = 1 << 30;
  }
  int maxv = 1;
  res[1] = num[1];
  for (int i = 2; i <= n; i++) {
    int s = bsch(1, n, num[i]);
    res[s] = num[i];
    if (maxv < s) maxv = s;
  }
  printf("%d\n", maxv);
  return 0;
}
