n = int(input()) lst = list(input().split()) num_s = [] for a in lst: if a.isnumeric(): num_s.append(int(a)) elif a == "+": n1 = num_s.pop(-1) n2 = num_s.pop(-1) num_s.append(n1 + n2) else: n1 = num_s.pop(-1) n2 = num_s.pop(-1) num_s.append(n2 - n1) print(num_s[0])