#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000010;
int a[MAXN], b[MAXN];
bool cmp(const int &a, const int &b) { return a > b; }
int main() {
  ios::sync_with_stdio(false);
  for (int n; ~scanf("%d", &n);) {
    for (int i = 1, x; i <= n; i++) {
      scanf("%d", &x);
      a[x] = i;
    }
    vector<int> rec;
    for (int i = 1, x; i <= n; i++) {
      scanf("%d", &x);
      x = a[x];
      int pos = upper_bound(rec.begin(), rec.end(), x, cmp) - rec.begin();
      if (pos == rec.size()) {
        rec.push_back(0);
      }
      rec[pos] = x;
    }
    cout << rec.size() << endl;
  }
  return 0;
}
