#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];
  }
  int h = n;
  for (int i = n; i >= 0; i--) {
    if (dp[i] > dp[height[h]]) {
      h = i;
    }
    height[i] = h;
  }
  int MAX = INT32_MIN;
  int MINIndex = 0;
  for (int i = 0; i < n; i++) {
    int index = height[i];
    if (dp[index] - dp[i] > MAX) {
      MINIndex = i;
      MAX = dp[index] - dp[i];
    }
  }
  int a = height[MINIndex];
  cout << -(accumulate(nums.begin(), nums.begin() + MINIndex, 0) +
            accumulate(nums.begin() + a, nums.end(), 0)) +
              accumulate(nums.begin() + MINIndex, nums.begin() + a, 0)
       << endl;
  return 0;
}
