#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int a[MAXN];
int n;
int pref[MAXN];
int main() {
  cin >> n;
  int best = 0;
  vector<pair<int, int> > all;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pref[i] = pref[i - 1] + a[i];
    for (auto& it : all) {
      it.first = max(it.first, a[i]);
    }
    all.emplace_back(a[i], pref[i - 1]);
    sort(all.begin(), all.end());
    map<int, int> mp;
    for (auto& it : all) {
      if (!mp.count(it.first))
        mp[it.first] = it.second;
      else
        mp[it.first] = min(mp[it.first], it.second);
    }
    all.clear();
    for (auto& it : mp) {
      all.emplace_back(it);
      best = max(best, pref[i] - it.second - it.first);
    }
  }
  cout << best;
  return 0;
}
