import Control.Monad.State

type Stack a = [a]

main = do
  expr <- getLine
  print $ reversePolish expr

pop :: State (Stack a) a
pop = do
  stack <- get
  put (tail stack)
  return $ head stack

push :: a -> State (Stack a) ()
push x = modify (x:)

reversePolish :: String -> Int
reversePolish exp = evalState (rp' (words exp)) []

rp' = foldr (>>) pop.map (\x -> if x `elem` ["*","+","-"] then op x else push (read x))

op "+" = calc (+)
op "-" = calc (-)
op "*" = calc (*)

calc f = do
  a <- pop
  b <- pop
  push $ b `f` a