#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1.0);
class segtree_sum_pointupdate {
 private:
 public:
  segtree_sum_pointupdate(const int64_t N) {
    SIZE = roundup_pow2(N);
    v.clear();
    v.resize(SIZE * 2, 0);
  }
  void update(const int64_t index, const int64_t number) {
    v[index + SIZE] = number;
    for (int64_t i = (index + SIZE) / 2; i; i = i / 2)
      v[i] = v[i * 2] + v[i * 2 + 1];
  }
  int64_t getnum(const int64_t index) { return v[index + SIZE]; }
  int64_t getsum(const int64_t L, const int64_t R) {
    return getsum_inner(L, R, 1, 0, SIZE);
  }

 private:
  int64_t getsum_inner(const int64_t queryL, const int64_t queryR,
                       const int64_t index, const int64_t segL,
                       const int64_t segR) {
    if (queryR <= segL || segR <= queryL) return 0;
    if (queryL <= segL && segR <= queryR) return v[index];
    return getsum_inner(queryL, queryR, index * 2, segL, (segL + segR) / 2) +
           getsum_inner(queryL, queryR, index * 2 + 1, (segL + segR) / 2, segR);
  }
  int64_t roundup_pow2(int64_t x) {
    x--;
    for (int64_t i = (int64_t)(0); i < (int64_t)(6); i++) x |= x >> (1LL << i);
    return x + 1;
  }
  int64_t SIZE;
  vector<int64_t> v;
};
segtree_sum_pointupdate seg(1);
int64_t minimize(vector<int64_t>& A, int64_t start, int64_t end) {
  assert(A[start] < 0 && A[end] < 0);
  int64_t ans = -A[start];
  int64_t cursor = start + 1;
  for (; 0 < A[cursor]; cursor++) {
    ans += A[cursor];
  }
  ans -= seg.getsum(cursor, end + 1);
  return ans;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64_t N;
  cin >> N;
  seg = segtree_sum_pointupdate(N);
  vector<int64_t> A(N), op(N - 1);
  int64_t first = -1, last = -1;
  for (int64_t i = (int64_t)(0); i < (int64_t)(N); i++) {
    string s;
    if (i)
      cin >> s;
    else
      s = "+";
    int64_t hugou = 1;
    if (s[0] == '-') {
      hugou *= -1;
      if (first == -1) first = i;
      last = i;
    }
    cin >> A[i];
    seg.update(i, A[i]);
    A[i] *= hugou;
  }
  if (first == last) {
    int64_t ans = 0;
    for (int64_t i = (int64_t)(0); i < (int64_t)(N); i++) ans += A[i];
    cout << ans << endl;
    return 0;
  }
  int64_t ans = 0;
  for (int64_t i = 0; i < first; i++) {
    assert(0 < A[i]);
    ans += A[i];
  }
  for (int64_t i = last + 1; i < N; i++) {
    assert(0 < A[i]);
    ans += A[i];
  }
  while (first != last) {
    int64_t secondlast = last - 1;
    int64_t ans2 = A[last];
    for (; 0 < A[secondlast]; secondlast--) ans2 += A[secondlast];
    int64_t m = minimize(A, first, last);
    int64_t m2 = minimize(A, first, secondlast) + ans2;
    if (m2 < m) {
      last = secondlast;
      ans += ans2;
      continue;
    }
    if (min(m, m2) <= -A[first]) {
      ans -= min(m, m2);
      cout << ans << endl;
      return 0;
    }
    ans += A[first++];
    for (; 0 < A[first]; first++) ans += A[first];
  }
  ans += A[first];
  cout << ans << endl;
  return 0;
}
