#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int& i : a) cin >> i;
  int ans = 0;
  for (int i = 0; i <= 30; i++) {
    int cur = 0;
    for (int j = 0; j < n; j++) {
      int val = (a[j] > i) ? -1e9 : a[j];
      cur = max(0, cur + val);
      ans = max(ans, cur - i);
    }
  }
  cout << ans;
}
