def solution(S):
    # write your code in Python 2.7
    
    parts = S.strip().split()
    
    # start with an integer
    try:
        stack = [int(parts.pop(0))]
    except Exception:
        return -1
    if stack[0] < 0:
        # range check
        return -1

    for part in parts:
        print stack
        if part == 'DUP':
            value = stack[-1]
        elif part == 'POP':
            if stack:
                stack.pop()
                continue
            else:
                return -1  # nothing to pop!
        elif part == '+':
            try:
                value = stack.pop() + stack.pop()
            except IndexError:
                # stack too small
                return -1
        elif part == '-':
            try:
                value = stack.pop() - stack.pop()
            except IndexError:
                # stack too small
                return -1
        else:
            # assume an integer
            value = int(part)

        if value < 0:
            # range check
            return -1
        stack.append(value)

    try:
        return stack[-1]
    except IndexError:
        # stack too small
        return -1

if __name__ == '__main__':
    import sys
    S = ' '.join(sys.argv[1:])
    print S
    print solution(S)
    
