// #pragma GCC target("avx2") #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include using namespace std; using P = pair; const int M = 1000000007; int main() { cin.tie(0); ios::sync_with_stdio(0); int n; cin >> n; vector a(n), mp(n); for (int i = 0; i < n; ++i) { cin >> a[i]; --a[i]; } for (int i = 0; i < n; ++i) { int b; cin >> b; --b; mp[b] = i; } vector idx(n); for (int i = 0; i < n; ++i) { a[i] = mp[a[i]]; idx[a[i]] = i; } int c = 0; for (int i = 0; i + 1 < n; ++i) { if (idx[i] > idx[i + 1]) ++c; } int ans = 0; while (c >> ans) ++ans; cout << ans << '\n'; return 0; }