import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.ArrayDeque

fun resolveOp(lhs: Int, op: String, rhs: Int): Int =
        when (op) {
            "+" -> lhs + rhs
            "*" -> lhs * rhs
            "-" -> lhs - rhs
            else -> throw UnsupportedOperationException()
        }

fun main(args: Array<String>) {
    val expr = BufferedReader(InputStreamReader(System.`in`))
            .readText()
            .trim()
            .split(regex = """\s+""".toRegex())

    val nuStack = ArrayDeque<Int>()

    for (item in expr) {
        if (item.matches("""\d+""".toRegex())) {
            nuStack.addLast(item.toInt())
        } else {
            val rhs = nuStack.removeLast()
            val lhs = nuStack.removeLast()
            nuStack.addLast(resolveOp(lhs, item, rhs))
        }
    }
    
    println(nuStack.first)

}
