#include <bits/stdc++.h>
int V[100010], N;
int main() {
  int i, submax, now, sum = 0;
  scanf("%d", &N);
  for (i = 1; i <= N; ++i) {
    scanf("%d", &V[i]);
    V[i] = -V[i];
    sum += V[i];
  }
  for (i = 1, submax = 0, now = 0; i <= N; ++i) {
    if (now > 0)
      now = V[i];
    else
      now += V[i];
    if (now < submax && now <= 0) {
      submax = now;
    }
  }
  printf("%d\n", sum - 2 * submax);
}
