import           Control.Applicative
import           Control.Monad.State

newtype Stack a = Stack [a]
    deriving (Read, Show)

push :: a -> State (Stack a) ()
push a = do
    s <- get
    case s of
        Stack []     -> put (Stack [a])
        Stack (x:xs) -> put (Stack (a:x:xs))
    return ()

pop :: State (Stack a) a
pop = do
    s <- get
    case s of
        Stack [] -> error "empty stack"
        Stack (x:xs) -> do
            put (Stack xs)
            return x

rpn :: [String] -> State (Stack Int) Int
rpn [] = pop
rpn (x:xs)
    | x == "+"  = calc (+) >> rpn xs
    | x == "-"  = calc (-) >> rpn xs
    | x == "*"  = calc (*) >> rpn xs
    | x == "/"  = calc div >> rpn xs
    | otherwise = do
        push $ read x
        rpn xs
  where
    calc op = do
        b <- pop
        a <- pop
        push (op a b)

main = do
    xs <- words <$> getLine :: IO [String]
    print $ evalState (rpn xs) (Stack [])

