#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m = 1;
  cin >> n;
  vector<vector<long long int>> v(1, vector<long long int>(1, 0));
  cin >> v[0][0];
  for (int i = 0; i < ((int)(n - 1)); i++) {
    char op;
    long long int t;
    cin >> op >> t;
    if (v.size() < m) v.push_back(vector<long long int>(0));
    if (op == '-') {
      v.back().push_back(-t);
      m++;
    } else {
      v.back().push_back(t);
    }
  }
  long long int ans = accumulate(v[0].begin(), v[0].end(), 0);
  long long int s1min = 0, s1s = 0;
  for (int j = 0; j < ((int)(v[1].size())); j++) {
    s1s += v[1][j];
    s1min = min(s1min, s1s);
  }
  ans += s1s - s1min * 2;
  for (int i = 2; i < v.size(); i++) {
    long long int smax = 0, smin = 0, ss = 0;
    for (int j = 0; j < ((int)(v[i].size())); j++) {
      ss += v[i][j];
      smin = min(smin, ss);
      smax = max(smax, ss);
    }
    ans += max(ss - smin * 2, 2 * smax - ss);
  }
  cout << ans << endl;
  return 0;
}
