#include <bits/stdc++.h>
using namespace std;
vector<int> a;
vector<int> d;
int solve() {
  int i, n = a.size();
  for (i = 0; i < n + 1; i++) d.push_back(2000000000);
  for (int i = 0; i < n; i++) {
    *lower_bound(d.begin(), d.end(), a[i]) = a[i];
  }
  for (int i = 0; i <= n; i++) {
    if (d[i] == 2000000000) {
      return i;
    }
  }
}
int ara[1000005], b[1000005], pos[1000005];
int main() {
  int n, i, x;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &ara[i]);
    pos[ara[i]] = i;
  }
  for (i = 1; i <= n; i++) {
    scanf("%d", &x);
    a.push_back(pos[x]);
  }
  reverse(a.begin(), a.end());
  cout << solve() << endl;
  return 0;
}
