from collections import defaultdict, deque from math import inf def main(): N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) graph = defaultdict(set) for a, b in zip(A, B): graph[a].add(a+b) q = deque([1]) dists = defaultdict(lambda: inf) dists[1] = 0 ans = 1 while q: cur = q.popleft() for n in graph[cur]: if dists[n] > dists[cur] + 1: dists[n] = dists[cur] + 1 q.append(n) ans = max(ans, n) print(ans) if __name__ == "__main__": main()