#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[100000];
  int n, j, i;
  int s = 0, c = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (j = 0; j < n; j++) {
    if (arr[j] == -1) c++;
    if (arr[j] == 1) {
      s++;
    }
    if (arr[j] > 1) s = s + arr[j];
    if (s > 0 && arr[j + 1] == -1) {
      s--;
      c--;
    }
  }
  cout << c << endl;
  return 0;
}
