#include <bits/stdc++.h>
using namespace std;
const int MAXN = int(1e5);
const long long INF = long long(1e15);
int n;
int A[MAXN + 5];
long long dp[MAXN + 5][2];
bool vis[MAXN + 5][2];
long long DP(int x, int typ) {
  if (x > n) return 0;
  if (vis[x][typ]) return dp[x][typ];
  vis[x][typ] = true;
  dp[x][typ] = INF * (typ ? -1 : 1);
  if (A[x] < 0 && x < n)
    for (int i = x + 1; i <= n; i++) {
      long long res1 = DP(x + 1, !typ);
      long long res2 = DP(i + 1, !typ);
      long long res3 = DP(i + 1, typ);
      if (!typ)
        dp[x][typ] = min(dp[x][typ], -(-A[x] + res1 - res2 + res3));
      else
        dp[x][typ] = max(dp[x][typ], -(-A[x] + res1 - res2 + res3));
    }
  else
    dp[x][typ] = A[x] + DP(x + 1, typ);
  return dp[x][typ];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    char str[2] = "";
    if (i - 1) scanf("%s", str);
    scanf("%d", &A[i]);
    if (str[0] == '-') A[i] *= -1;
  }
  printf("%lld\n", DP(1, 0));
  return 0;
}
