#include <bits/stdc++.h>
using namespace std;
int _toggle(int N, int pos) { return N = N ^ (1 << pos); }
int _set(int N, int pos) { return N = N | (1 << pos); }
int _reset(int N, int pos) { return N = N & ~(1 << pos); }
bool _check(int N, int pos) { return (bool)(N & (1 << pos)); }
bool _upper(char a) { return a >= 'A' && a <= 'Z'; }
bool _lower(char a) { return a >= 'a' && a <= 'z'; }
bool _digit(char a) { return a >= '0' && a <= '9'; }
int dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
int dy[] = {0, 0, 1, -1, -1, 1, -1, 1};
int face[1000010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    face[a] = i;
  }
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    a.push_back(face[b]);
  }
  reverse(a.begin(), a.end());
  const int INF = 1e9;
  vector<int> dp(n + 1, INF);
  dp[0] = -INF;
  for (int i = 0; i < n; i++) {
    int j = upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
    if (dp[j - 1] < a[i] && a[i] < dp[j]) {
      dp[j] = a[i];
    }
  }
  int ans = 0;
  for (int i = 0; i <= n; i++) {
    if (dp[i] < INF) {
      ans = i;
    }
  }
  cout << ans << '\n';
}
