#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, ans = 0; cin >> n; vector a(n), b(n), c(n); vector used(n); for(auto &&v : a) cin >> v, v--; for(int i = 0; i < n; i++){ cin >> b[i]; c[--b[i]] = i; } for(int i = 0; i < n; i++){ a[i] = c[a[i]]; if(a[i] == 0 || !used[a[i] - 1]){ ans++; } used[a[i]] = true; } if(__builtin_popcount(ans) != 1) ans <<= 1; cout << __lg(ans) << '\n'; }