#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 5;
int pos[M], dp[M];
int main() {
  int n;
  scanf("%d", &n);
  memset(dp, 31, sizeof dp);
  for (int i = n - 1; ~i; i--) {
    int x;
    scanf("%d", &x);
    pos[x] = i;
  }
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    dp[lower_bound(dp, dp + M, pos[x]) - dp] = pos[x];
  }
  return cout << (lower_bound(dp, dp + M, M) - dp) << endl, 0;
}
