import sys input = sys.stdin.readline from collections import * N = int(input()) A = list(input().split()) q = deque([]) for Ai in A: if Ai=='+': a = q.pop() b = q.pop() q.append(a+b) elif Ai=='-': a = q.pop() b = q.pop() q.append(b-a) else: q.append(int(Ai)) print(q[0])