#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int SZ = 2e5 + 10;
int n;
int num[SZ];
int main() {
  scanf("%d", &n);
  int ans = 0;
  for (int i = 1; i <= n; i++) scanf("%d", &num[i]);
  for (int i = 1; i <= 30; i++) {
    bool flag = 0;
    int sum = 0;
    for (int j = 1; j <= n; j++) {
      if (num[j] > i) {
        sum = 0;
      }
      if (num[j] <= i) {
        sum += num[j];
        if (sum < 0)
          sum = 0;
        else
          ans = max(ans, sum - i);
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
