n=int(input()) A=list(map(str,input().split())) stack=[] for i in range(len(A)): if A[i] == "+": stack.append(stack.pop()+stack.pop()) elif A[i] == "-": t=stack[-2]-stack[-1] stack.pop() stack.pop() stack.append(t) else: stack.append(int(A[i])) print(stack[-1])