#include <bits/stdc++.h>
using namespace std;
int n;
int in[2 * 1000000], mas[2 * 1000000];
pair<int, int> num[2 * 1000000];
vector<int> len;
void input(int x) {
  vector<int>::iterator it = lower_bound(len.begin(), len.end(), x);
  if (it == len.end()) {
    len.push_back(x);
  } else {
    len[it - len.begin()] = x;
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> in[i];
    num[in[i]].first = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> mas[i];
    num[mas[i]].second = i;
  }
  for (int i = 1; i <= n; i++) {
    int x = num[in[i]].second;
    in[i] = n - i + 1;
    mas[x] = n - i + 1;
  }
  mas[0] = 2000000;
  len.push_back(-2000000);
  for (int i = 1; i <= n; i++) {
    input(mas[i]);
  }
  cout << len.end() - len.begin() - 1;
}
