import scala.io.StdIn.readLine

object Main extends App {
  def calc(op:String,x:Int,y:Int) = {
    op match {
      case "+" => x+y
      case "-" => x-y
      case "*" => x*y
    }
  }

  val l = readLine.split(" ").toList

  def revP(l:List[String],stack:List[Int]):Int =  {
    l match {
      case Nil => stack(0)
      case hd::tl =>
        val stack2 =
          if(hd.forall(_.isDigit)) hd.toInt::stack
          else {
            val x::y::tail = stack
            calc(hd,y,x)::tail
          }
        revP(tl,stack2)
    }
  }

  println(revP(l,Nil))

}