#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
const long long mxn = 1e5 + 10;
long long a[mxn];
long long n;
long long dp[mxn][2][100];
long long solve(long long i, long long status, long long leave) {
  if (i >= n) return -leave;
  long long x = leave;
  if (x < 0) x += 60;
  long long& ans = dp[i][status][leave];
  if (ans != -1) return ans;
  ans = -1;
  if (status == 0) {
    ans = max({a[i] + solve(i + 1, 1, max(a[i], leave)), solve(i + 1, 0, 0)});
  } else {
    ans = max({a[i] + solve(i + 1, 1, max(a[i], leave)), solve(n, 1, leave)});
  }
  return ans;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  cout << solve(0, 0, 0) << "\n";
  return 0;
}
