#yuki1135 n=int(input()) a=input().split() stack=[] for s in a: if s=='+': stack[-2]+=stack[-1] stack.pop() elif s=='-': stack[-2]-=stack[-1] stack.pop() else: stack.append(int(s)) print(stack[0])