#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e6 + 6;
long long int arr[N], n, x, y, mx;
int main() {
  cin >> n;
  long long int res = 0;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    x += arr[i];
    y += arr[i];
    if (y < 0) y = 0;
    mx = max(mx, y);
  }
  cout << (2 * mx - x) << "\n";
  return 0;
}
