solve :: [Int] -> [String] -> Int
solve cs [] = head cs
solve (a:b:cs) ("+":ys) = solve ((a+b):cs) ys
solve (a:b:cs) ("-":ys) = solve ((b-a):cs) ys
solve (a:b:cs) ("*":ys) = solve ((a*b):cs) ys
solve cs (y:ys)	= solve	((read y):cs) ys

main = getContents >>= print . solve [] . words
