#include using namespace std; void fast_io() { ios::sync_with_stdio(false); std::cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; vector a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } const int M = 1e6 + 1; vector> g(M); for (int i = 0; i < n; i++) { cin >> b[i]; g[a[i]].push_back(a[i] + b[i]); } int ans = 1; deque dq{1}; vector vis(M); vis[1] = true; while (!dq.empty()) { int u = dq.front(); dq.pop_front(); ans = max(ans, u); for (int v : g[u]) { if (vis[v]) { continue; } dq.push_back(v); vis[v] = true; } } cout << ans << endl; }