N=int(input()) x=[] for a in input().split(): if a=="+": x[-2]+=x[-1] x.pop() elif a=='-': x[-2]-=x[-1] x.pop() else: x.append(int(a)) print(x[0])