# Arup Guha
# 9/1/2026
# Solution to 2026 UCF Locals Problem: Charge On

# Get list.
n = int(input())
vals = [int(x) for x in input().split()]

# These are actually beyond what the real answers could be.
lo = 0
hi = 2000000000

# Run binary search.
while lo < hi:

    # What we'll try for the charge.
    mid = (lo+hi)//2

    # curC is the charge.
    canDo = True
    curC = mid

    # Simulate the charging.
    for i in range(n):

        # New charge.
        curC = min(mid, curC + vals[i])

        # We didn't make it.
        if curC <= 0:
            canDo = False
            break

    # Update hi since answer is mid or lower.
    if canDo:
        hi = mid

    # In this case answer is mid+1 or higher.
    else:
        lo = mid+1

# This is our answer.
print(lo)
