from collections import deque N = int(input()) A = list(map(int,input().split())) B = list(map(int,input().split())) G = {1:set()} for i in range(N): a = A[i] b = B[i] if a not in G: G[a] = set() if a+b not in G[a]: G[a].add(a+b) if a+b not in G: G[a+b] = set() que = deque([1]) visited = set([1]) while que: x = que.popleft() for y in G[x]: if y not in visited: visited.add(y) que.append(y) print(max(visited))