#include <bits/stdc++.h>
using namespace std;
inline void boostIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int n, a[100100], dp[100100][2][2];
int solve(int idx = 0, bool prefix = true, bool suffix = false) {
  if (idx >= n) return 0;
  int& ret = dp[idx][prefix][suffix];
  if (~ret) return ret;
  ret = solve(idx + 1, prefix, suffix) + a[idx] * ((prefix || suffix) ? -1 : 1);
  if (prefix) {
    ret = max(ret, solve(idx, false, suffix));
  }
  if (!prefix && !suffix) {
    ret = max(ret, solve(idx, prefix, true));
  }
  return ret;
}
int main() {
  boostIO();
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  memset(dp, -1, sizeof(dp));
  cout << solve() << endl;
  return 0;
}
