#include <bits/stdc++.h>
using namespace std;
const long long N = 1e18 + 2;
int x1, Y1, Y3, x3, Y2, x2;
int ans;
vector<int> vec;
int n, ret1 = 0, ret2 = 0;
int solve(int i, int money, int cotton) {
  if (i == n) return money;
  ret1 = 0, ret2 = 0;
  if (money - vec[i] >= 0)
    ret1 = max(solve(i + 1, money - vec[i], cotton + 1),
               solve(i, money - vec[i], cotton + 1));
  else
    ret1 = money;
  if (cotton - 1 >= 0)
    ret2 = solve(i + 1, money + vec[i], cotton - 1),
    solve(i, money + vec[i], cotton - 1);
  else
    ret2 = money;
  return max({solve(i + 1, money, cotton), ret1, ret2});
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    vec.push_back(x);
  }
  cout << solve(0, 1000, 0);
  return 0;
}
