#include <bits/stdc++.h>
using namespace std;
constexpr int64_t kMod = 1e9 + 7;
int main() {
  std::vector<int> v;
  int n;
  cin >> n;
  int64_t answer = 0;
  cin >> answer;
  for (int i = 0; i < n - 1; i++) {
    char c;
    int x;
    cin >> c >> x;
    int new_x = x * (c == '+' ? 1 : -1);
    if (v.empty()) {
      v.push_back(new_x);
    } else {
      if (new_x > 0 && v.back() >= 1) {
        v.back() += new_x;
        continue;
      }
      if ((new_x > 0 && v.back() < 0) || (new_x < 0 && v.back() > 0)) {
        v.push_back(new_x);
        continue;
      }
      v.push_back(0);
      v.push_back(new_x);
    }
  }
  if (v.back() < 0) {
    v.push_back(0);
  }
  if (v.size() && v[0] > 0) {
    answer += v[0];
    v.erase(v.begin());
  }
  int64_t sum = 0;
  for (int i = 0; i < (int)v.size(); i++) {
    sum += v[i];
  }
  int64_t best_ans = sum;
  int64_t cur_sum = 0;
  for (int i = (int)v.size() - 1; i >= 0; i--) {
    assert(v[i] >= 0);
    assert(i > 0);
    assert(v[i - 1] < 0);
    sum -= v[i];
    sum -= v[i - 1];
    best_ans = max(best_ans, cur_sum - v[i] + v[i - 1] + sum);
    cur_sum += v[i];
    cur_sum -= v[i - 1];
    i--;
  }
  cout << best_ans + answer << endl;
  return 0;
}
