#include <bits/stdc++.h>
using namespace std;
int n, flag[100010], w[100010], nxt[100010];
long long ans, now, s[100010];
char S[10];
int main() {
  scanf("%d", &n);
  memset(flag, 0, sizeof(flag));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &w[i]);
    if (i <= n - 1) {
      scanf("%s", S + 1);
      if (S[1] == '-') flag[i + 1] = 1;
    }
  }
  s[0] = 0;
  for (int i = 1; i <= n; i++) s[i] = s[i - 1] + w[i];
  now = n + 1;
  for (int i = n; i; i--) {
    nxt[i] = now;
    if (flag[i]) now = i;
  }
  ans = 1000000000000000000LL;
  now = 0;
  for (int i = 1; i <= n; i++)
    if (flag[i]) {
      ans = min(ans, now + s[nxt[i] - 1] - s[i - 1]);
      now += w[i];
    }
  printf("%lld", s[n] - ans * 2);
  return 0;
}
