from collections import deque N = int(input()) sushi = [ int(i) for i in input().split() ] sushi.insert(0,0) res = [0] * (N + 1) q = deque([]) res[0] = 0 q.append(0) taboo = False while q: pos = q.popleft() for next_pos in range(pos+1,N+1): if taboo: if next_pos == pos + 1: continue if res[next_pos] < res[pos] + sushi[next_pos]: q.append(next_pos) res[next_pos] = res[pos] + sushi[next_pos] taboo = True print(max(res))