from collections import deque N=int(input()) A=input().split() X=deque() for a in A: if a=="+": q=X.pop() p=X.pop() X.append(p+q) elif a=="-": q=X.pop() p=X.pop() X.append(p-q) else: X.append(int(a)) print(X[0])