#include <bits/stdc++.h>
using namespace std;
long long n, a, cnt = 0;
long long pol, x;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  pol = 0;
  while (n--) {
    cin >> a;
    if (a >= 0) {
      if (pol < 0) pol = 0;
      pol += a;
    } else {
      pol += a;
      if (pol < 0) {
        if (x > 0)
          cnt += -pol;
        else
          cnt += x - pol;
      }
      x = pol;
    }
  }
  cout << cnt;
}
