import scala.io.StdIn.readLine

object Main extends App {
  val arr = readLine.split(" ")
  val stack = scala.collection.mutable.Stack[Int]()

  for (e <- arr) e match {
    case e if e == "+" | e == "-" | e == "*" =>
      val calc = stringToOperator(e)(stack.pop(), stack.pop())
      stack.push(calc)
    case i =>
      stack.push(i.toInt)
  }

  println(stack.head)

  def stringToOperator(op: String)(n: Int, m: Int): Int = op match {
    case "+" => m + n
    case "-" => m - n
    case "*" => m * n
    case _ => throw new IllegalArgumentException
  }
}
