#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int dp[N][2][2];
bool vis[N][2][2];
int arr[N];
int n;
int solve(int i, bool start, bool end) {
  if (i == n) return 0;
  if (vis[i][start][end]) return dp[i][start][end];
  vis[i][start][end] = true;
  int ans;
  if (start && end) {
    ans = max(arr[i] + solve(i + 1, start, end),
              -arr[i] + solve(i + 1, false, end));
  } else if (start) {
    ans = max(max(arr[i] + solve(i + 1, true, true),
                  -arr[i] + solve(i + 1, true, false)),
              max(arr[i] + solve(i + 1, false, false),
                  -arr[i] + solve(i + 1, false, true)));
  } else if (end) {
    ans = -arr[i] + solve(i + 1, start, end);
  } else {
    ans = max(arr[i] + solve(i + 1, start, end),
              -arr[i] + solve(i + 1, start, true));
  }
  return dp[i][start][end] = ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  printf("%d", solve(0, true, false));
  return 0;
}
