N=int(input()) V=list(map(int,input().split())) DP=[0 for i in range(N+1)] DP[1]=V[0] for i in range(1,N): max_num=max(DP[:i]) DP[i+1]=max([max_num+V[i],max_num]) print(max(DP))