#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, st, cmax = 0, ans = 0;
  cin >> n;
  int A[n];
  bool B[31];
  for (int g = 0; g < n; g++) {
    cin >> A[g];
    if (A[g] > 0) B[A[g]] = 1;
  }
  for (st = 1; st <= 30; st++) {
    cmax = 0;
    if (B[st]) {
      for (int i = 0; i < n; i++) {
        if (A[i] > st)
          cmax = 0;
        else
          cmax = max(cmax + A[i], 0);
        ans = max(ans, cmax - st);
      }
    }
  }
  cout << ans;
  return 0;
}
