
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(" ")

  def revP(n:Int,stack:List[Int]):Int =  {
    if(n==l.length) stack(0)
    else {
      val s = l(n)
      val stack2 =
        if(s.forall(_.isDigit)) s.toInt::stack
        else {
          val x::y::tail = stack
          calc(s,y,x)::tail
        }
      revP(n+1,stack2)
    }
  }

  println(revP(0,List()))

}