N = gets.to_i A = gets.chomp.split stack = [] A.each do |a| if a == '+' u, v = stack.pop(2) stack << u + v elsif a == '-' u, v = stack.pop(2) stack << u - v else stack << a.to_i end end puts stack.first