import sys

n = int(next(sys.stdin).strip())
items = next(sys.stdin).strip().split()

cache = {(i, i + 1): (int(items[2 * i]), int(items[2 * i])) for i in range(n)}


def value(l, r):
    if (l, r) in cache:
        return cache[(l, r)]

    lower, upper = float('inf'), float('-inf')
    for c in range(l + 1, r):
        ll, lu = value(l, c)
        rl, ru = value(c, r)
        op = items[2 * c - 1]
        if op == '+':
            lower = min(lower, ll + rl)
            upper = max(upper, lu + ru)
        elif op == '-':
            lower = min(lower, ll - ru)
            upper = max(upper, lu - rl)

    cache[(l, r)] = (lower, upper)
    return lower, upper

lower, upper = value(0, n)
print(upper)
