#include <bits/stdc++.h>
using namespace std;
int a[int(1e5 + 5)], n, dyn1, dyn2, dyn3, new_dyn1, new_dyn2, new_dyn3;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    new_dyn1 = dyn1 - a[i];
    new_dyn2 = max(dyn2 + a[i], dyn1 + a[i]);
    new_dyn3 = max(dyn3 - a[i], dyn2 - a[i]);
    dyn1 = new_dyn1;
    dyn2 = new_dyn2;
    dyn3 = new_dyn3;
  }
  cout << max(dyn1, max(dyn2, dyn3));
  return 0;
}
