#include using namespace std; #define all(x) (x).begin(),(x).end() #define rep(i,n) for(int i=0;i<(n);i++) #define rep3(i,m,n) for(int i=(m);i<(n);i++) #define foreach(x,a) for(auto& (x) : (a) ) #define endl '\n' #define dump(x) cout << #x << " = " << (x) << endl; #define YES(n) cout << ((n) ? "YES" : "NO" ) << endl #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl #define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl #define Possible(n) cout << ((n) ? "Possible" : "Impossible" ) << endl #define pb(a) push_back(a) #define sz(x) ((int)(x).size()) #define in(a,us) (us).find(a)!=(us).end() template using Vec = vector; template using P = pair; template using Tpl = tuple; using ll = long long; using ld = long double; using Pii = P; using Pll = P; using Tiii = Tpl; using Tll = Tpl; using Vi = Vec; using VVi = Vec; template using umap = unordered_map; template using uset = unordered_set; using Graph = VVi; int main(){ cin.tie(0)->sync_with_stdio(0); int n; cin >> n; Vi a(n),b(n); rep(i,n) cin >> a[i]; rep(i,n) cin >> b[i]; umap um; rep(i,n) um[a[i]] = i; Vi c(n); rep(i,n) c[i] = um[b[i]]; uset s; rep(i,n){ if (in(c[i]-1,s)) { s.erase(s.find(c[i]-1)); s.insert(c[i]); } else { s.insert(c[i]); } } int sz = s.size(); int ans = 0; while (sz>1){ sz = (sz+1)/2; ans++; } cout << ans << endl; }