#include <bits/stdc++.h>
using namespace std;
const int mxn = 1e5 + 2;
const int inf = 1e9 + 7;
int main() {
  int n, a[mxn];
  long long ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int j = 0; j < 31; j++) {
    long long cure = 0, best = 0;
    for (int i = 0; i < n; i++) {
      int val;
      if (a[i] > j)
        val = -inf;
      else
        val = a[i];
      cure += val;
      best = min(best, cure);
      ans = max(ans, (cure - best) - j);
    }
  }
  cout << ans << endl;
  return 0;
}
