#include <bits/stdc++.h>
using namespace std;
inline char nc() {
  static char b[1 << 12], *s = b, *t = b;
  return s == t && (t = (s = b) + fread(b, 1, 1 << 12, stdin), s == t) ? -1
                                                                       : *s++;
}
template <class T>
inline void read(T &x) {
  char b = nc();
  x = 0;
  for (; !isdigit(b); b = nc())
    ;
  for (; isdigit(b); b = nc()) x = x * 10 + b - '0';
}
inline int read() {
  char b = nc();
  for (; b != '-' && b != '+'; b = nc())
    ;
  return b == '-' ? -1 : 1;
}
int n;
long long f0, f1, f2;
int main() {
  read(n);
  read(f0);
  f1 = f2 = -1e9;
  for (int a, op, i = 1; i < n; ++i) {
    op = read();
    read(a);
    f0 += a * op;
    f1 -= a * op;
    f2 += a * op;
    if (op == -1) {
      if ((f1) > f2) f2 = (f1);
      ;
      if ((f0) > f1) f1 = (f0);
      ;
    }
    if ((f2) > f1) f1 = (f2);
    ;
    if ((f1) > f0) f0 = (f1);
    ;
  }
  printf("%lld\n", f0);
  return 0;
}
