N = int(input()) V = list(map(int, input().split())) dp1 = [0]*N dp2 = [0]*N if len(V) == 1: print(V[0]) exit() dp1[0] = V[0] dp1[1] = V[0] dp2[1] = V[1] for i in range(2, N): dp1[i] = max(V[i] + max(dp1[:i-1]), dp1[i-1]) dp2[i] = max(V[i] + max(dp2[:i-1]), dp2[i-1]) print(max(max(dp1), max(dp2)))