n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) edges = {} for a, b in zip(A, B): edges.setdefault(a, []).append(a + b) st = [1] se = {1} while st: u = st.pop() for v in edges.get(u, []): if v not in se: st.append(v) se.add(v) print(max(se))