#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 69;
const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
int n, ip;
pair<int, int> arr[MAXN];
set<int> s;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> ip, arr[ip].first = i;
  for (int i = 1; i <= n; i++) cin >> ip, arr[ip].second = i;
  sort(arr + 1, arr + n + 1, cmp);
  reverse(arr + 1, arr + n + 1);
  for (int i = 1; i <= n; i++) {
    if (s.lower_bound(arr[i].first) != s.end())
      s.erase(s.lower_bound(arr[i].first));
    s.insert(arr[i].first);
  }
  cout << s.size() << "\n";
}
