#include <bits/stdc++.h>
using namespace std;
int a[1001 * 1001], b[1001 * 1001], c[1001 * 1001];
set<int> st;
set<int>::iterator it;
int main() {
  int i, n;
  while (scanf("%d", &n) > 0 && n) {
    for ((i) = 0; (i) < (n); (i)++) {
      scanf("%d", &a[i]);
      a[i]--;
      c[a[i]] = i;
    }
    for ((i) = 0; (i) < (n); (i)++) {
      scanf("%d", &b[i]);
      b[i]--;
      b[i] = c[b[i]];
    }
    st.clear();
    for (i = 0; i < n; i++) {
      st.insert(b[i]);
      it = st.find(b[i]);
      if (it != st.begin()) {
        it--;
        st.erase(it);
      }
    }
    cout << st.size() << endl;
  }
  return 0;
}
