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