fun main(args: Array<String>) {
    val array = readLine()
        ?.split(" ".toRegex())
        ?.toTypedArray()
        ?: arrayOf("")
    val stack = MyStack<Int>()
    array.forEach {
        try {
            val num = it.toInt()
            stack.push(num)
        } catch (e: NumberFormatException) {
            when (it) {
                "+" -> {
                    val b = stack.pop()
                    val a = stack.pop()
                    stack.push(a + b)
                }
                "-" -> {
                    val b = stack.pop()
                    val a = stack.pop()
                    stack.push(a - b)
                }
                "*" -> {
                    val b = stack.pop()
                    val a = stack.pop()
                    stack.push(a * b)
                }
            }
        }
    }
    println(stack.pop())
}

class MyStack<T> {
    private val list = mutableListOf<T>()

    fun push(newVal: T) {
        list.add(newVal)
    }

    fun pop(): T {
        val retVal = list.last()
        list.removeAt(list.lastIndex)
        return retVal
    }
}
