N = int(input()) A = input().split() stack = [] for a in A: if a == '+': stack.insert(0, stack.pop(0) + stack.pop(0)) elif a == '-': stack.insert(0, stack.pop(0) - stack.pop(0)) else: stack.append(int(a)) print(stack[0])