import math import sys def S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int, sys.stdin.readline().rstrip().split()) def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) n = I() a = LS() stack = [] for i in a: if i in "+-": y = stack.pop() x = stack.pop() if i == "+": stack.append(x+y) else: stack.append(x-y) else: stack.append(int(i)) print(stack[0])