#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  if (e == 0) return 1;
  if (e % 2 == 0) {
    T t = bigmod(p, e / 2, M);
    return (t * t) % M;
  }
  return (bigmod(p, e - 1, M) * p) % M;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0ll) {
    x = 1ll, y = 0ll;
    return a;
  }
  long long ret = exgcd(b, a % b, y, x);
  y -= (a / b) * x;
  return ret;
}
long long rem[100009];
long long mod[100009];
long long CRT1(int n) {
  for (int i = 0; i < n; i++) rem[i] %= mod[i];
  long long ret = rem[0], LCM = mod[0];
  for (int i = 1; i < n; i++) {
    long long x, y;
    long long gd = exgcd(mod[i], -LCM, x, y);
    long long dif = ret - rem[i];
    if (dif % gd != 0) return -1;
    LCM = LCM / gd * mod[i];
    if (LCM < 0) LCM = -LCM;
    x = x * dif / gd;
    ret = (mod[i] * x + rem[i]) % LCM;
    if (ret < 0ll) ret += LCM;
  }
  return ret;
}
int pos[1000009];
int arr[1000009];
int val[1000009];
int main() {
  int i, j;
  int n, m, k, num;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &num);
    pos[num] = n - i;
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &num);
    arr[i] = pos[num];
  }
  int ind = 0;
  for (i = 1; i <= n; i++) {
    if (ind == 0 || arr[i] > val[ind - 1])
      val[ind++] = arr[i];
    else {
      int lp = lower_bound(val, val + ind, arr[i]) - val;
      if (lp < ind) val[lp] = arr[i];
    }
  }
  printf("%d\n", ind);
  return 0;
}
