n = int(input())
a = list(map(int,input().split()))

dp = [[-1]*1000 for i in range(n+1)]
dp[0][0] = 1000


for i in range(n):
    for j in range(1000):
        dp[i+1][j] = max(dp[i+1][j],dp[i][j])
        if dp[i+1][j] >= a[i]:
            dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j]-a[i])
        
    for j in range(999,0,-1):
        if dp[i+1][j] >= 0:
             dp[i+1][j-1] = max(dp[i+1][j-1],dp[i+1][j]+a[i])
print(max(dp[-1]))
