import scala.io.StdIn.readLine;
object Main {
    def main(args: Array[String]): Unit = {
        val stack = new LongStack(100)
       for (i <- readLine.split(" ")) {
            if (i  == "+") {
                stack.push(stack.pop + stack.pop);
            } else if (i == "*"){
                stack.push(stack.pop * stack.pop);
            } else if (i == "-") {
                val a = stack.pop;
                stack.push(stack.pop - a);
            } else {
                stack.push(i.toLong);
            }
        }
        println(stack.pop);
    }
}
class LongStack(size: Int) {
    val arr = new Array[Long](size);
    var ptr = 0;
    def push(e: Long): Unit = if (ptr < size) {
        arr(ptr) = e;
        ptr += 1;
    }
    def pop: Long = if (ptr > 0) {
        ptr -= 1;
        arr(ptr);
    } else {
        throw new NoSuchElementException();
    }
}
