#include #include using namespace std; using ll = long long; using mint = atcoder::modint998244353; using maxt = atcoder::modint1000000007; int main() { int N; cin >> N; vector A(N); for(int &o : A) { cin >> o; } vector B(N); for(int &o : B) { cin >> o; } int tmp = 1; for(int i = 1; i <= N; i++) { tmp *= i; } int ans = 0; while(tmp > 0) { int H = 1; for(int i = 0; i < N; i++) { if(H == A.at(i)) { H += B.at(i); } } ans = max(ans, H); tmp--; next_permutation(A.begin(), A.end()); next_permutation(B.begin(), B.end()); } cout << ans << endl; }