main :: IO ()
main = getLine >>= print . head . foldl calc [] . words

calc :: [Int] -> String -> [Int]
calc xs y
  | y == "+" = init2 ++ [last2 + last1]
  | y == "-" = init2 ++ [last2 - last1]
  | y == "*" = init2 ++ [last2 * last1]
  | otherwise = xs ++ [read y]
  where
    last1 = last xs
    last2 = last . init $ xs
    init2 = init . init $ xs

