#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> nums;
  vector<int> dp(n + 1, 0);
  vector<int> height(n + 1, 0);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    nums.push_back(x);
  }
  for (int i = 1; i <= n; i++) dp[i] = dp[i - 1] + nums[i - 1];
  for (int i = n, h = n; i >= 0; i--) {
    if (dp[i] > dp[height[h]]) h = i;
    height[i] = h;
  }
  int MINIndex = 0;
  for (int i = 0, MAX = INT32_MIN; i < n; i++) {
    if (dp[height[i]] - dp[i] > MAX) {
      MINIndex = i;
      MAX = dp[height[i]] - dp[i];
    }
  }
  cout << -(accumulate(nums.begin(), nums.begin() + MINIndex, 0) +
            accumulate(nums.begin() + height[MINIndex], nums.end(), 0)) +
              accumulate(nums.begin() + MINIndex,
                         nums.begin() + height[MINIndex], 0)
       << endl;
  return 0;
}
