n=int(input()) a=list(input().split()) stack=[] for i in a: if i.isdecimal(): stack.append(int(i)) elif i=="+": x=stack.pop() y=stack.pop() stack.append(x+y) else: x=stack.pop() y=stack.pop() stack.append(x-y) print(stack[0])