#include <bits/stdc++.h>
using namespace std;
const int MN = 1e6 + 10;
const int INF = 1e9 + 10;
int arr[MN], a[MN], place[MN];
int n;
int lis[MN];
void input() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    --a[i];
  }
  int t;
  for (int j = 0; j < n; ++j) {
    cin >> t;
    --t;
    place[t] = j;
  }
  for (int i = 0; i < n; ++i) arr[i] = place[a[i]];
}
void solve() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  fill_n(lis, MN, INF);
  for (int i = n - 1; i >= 0; --i) {
    int t = lower_bound(lis, lis + MN, arr[i]) - lis;
    lis[t] = arr[i];
  }
  int ans;
  for (ans = 0; ans < MN && lis[ans] < INF; ++ans)
    ;
  cout << ans << endl;
}
int main() {
  input();
  solve();
  return 0;
}
