object Main extends App{
    // Your code here!
    import scala.io.Source.stdin
    def calc_exp(args: List[String]): Int = {
        val stack = new scala.collection.mutable.Stack[Int]
        def tryToInt( s: String ) = scala.util.Try(s.toInt).toOption
        def calc(e: String): Unit = {
            val element = tryToInt(e)
            element match {
                case Some(i) => {stack.push(i); return}
                case None => -1
            }
            var result = 0
            e match {
                case "+" => result = stack.pop + stack.pop
                case "-" => result = -stack.pop + stack.pop
                case "*" => result = stack.pop * stack.pop
                case _ => -1
            }
            stack.push(result)
        }
        args.foreach(calc)
        stack.pop
    }
    val input = scala.io.StdIn.readLine.split(" ").toList
    println(calc_exp(input))
}

