N = int(input()) A = input().split() stack = [] for i in range(N): if A[i]=="+": b = stack.pop() a = stack.pop() stack.append(a+b) elif A[i]=="-": b = stack.pop() a = stack.pop() stack.append(a-b) else: stack.append(int(A[i])) print(stack[-1])