N = int(input()) A = list(input().split()) stack = [] for a in A: if a == "+" or a == "-": b = stack.pop() c = stack.pop() if a == "+": d = b + c else: d = c - b stack.append(d) else: stack.append(int(a)) print(stack[0])