The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.

Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.

If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.

Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.
The first line of input will contain an integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>), the number of events. The next line will contain *n* space-separated integers.

If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.
# Problem: https://codeforces.com/problemset/problem/427/A
# Answer: 

# One police officer and respond to one crime.
# If no police officer is available, the crime goes unpunished.
# Find number of unpunished crimes.

# First input is number of events.
# If an integer is -1, a crime happens.
# If an integer is 1, an officer is hired.

# Note: the police department starts off with 0 officers.
# so if you get  -1 -1 1, then 2 crimes have happened,
# even though one officer was hired.

# The events variable will track the number of events,
# specifically the crimes and the department's ability
# to respond to such crimes.
events = int(input())

# The crimeAndPunishment variable houses a list of the
# various events that will happen as ints.
crimeAndPunishment = [int(i) for i in input().split()]

# To solve this problem I will keep track of a reservoir
# of available officers. If there are none available, we
# will add 1 to the unpunished crime counter. But if there
# is an officer available, we will punish the crime.
availableOfficers = 0
unpunishedCrimes = 0
for n in range(len(crimeAndPunishment)):
    
    # If the integer is a non-negative number, then the number
    # represents the number of officers we add to the department.
    # We add that number to our available officers.
    if crimeAndPunishment[n] >= 1:
        availableOfficers += crimeAndPunishment[n]
    
    # If the integer is a negative number, then a crime happened.
    # Only one crime can happen at a time.
    # First we check to see if we have available officers. If we
    # have zero officers, then we add 1 to unpunished crimes. If
    # we have available officers, we subtract one officer from the
    # reserve list so he can investigate the crime.
    if crimeAndPunishment[n] == -1:
        if availableOfficers == 0:
            unpunishedCrimes += 1
        elif availableOfficers > 0:
            availableOfficers -= 1
            # Note: the reason we don't subtract 1 from the reserve
            # is because doing so might create a negative reserve
            # of officers. In this problem the lowest the
            # reserve can go is 0. So first check to see if the
            # reserve has at least 1 person in it (reserve > 0)
            # and if it does, then take that person out because
            # he is responding to the crime. If nobody is in
            # reserve, just keep the availableOfficers number 
            # at 0.

# Print the number of unpunished crimes that happen,
# or the crimes that happen where officers aren't
# available to respond.
print(unpunishedCrimes)       
        
        
        
        
    