n = int(input()) l = input().split() i = 0 while i != n: if l[i] in '+-': l[i] = str(eval(l[i-2]+l[i]+l[i-1])) l.pop(i-2) l.pop(i-2) i-=2 n-=2 i+=1 print(l[0])