class Stack<T>(size: Int) {

    private val elements = arrayOfNulls<Any?>(size)

    private var top = 0

    private fun isEmpty() = top == 0

    private fun isFull() = elements.size == top

    fun push(element: T) {
        if (isFull()) throw Exception("error")
        elements[top] = element
        top++
    }

    @Suppress("UNCHECKED_CAST")
    fun pop() : T {
        if (isEmpty()) throw Exception("error")
        val element = elements[top - 1]
        elements[top - 1] = null
        top--
        return element as T
    }
}

fun isNumber(num: String): Boolean {
    try {
        num.toInt()
    } catch (e: NumberFormatException) {
        return false
    }
    return true
}

fun calc(firstNumber: Int, secondNumber: Int, operator: String): Int {
    when (operator) {
        "+" -> return firstNumber + secondNumber
        "-" -> return firstNumber - secondNumber
        "*" -> return firstNumber * secondNumber
    }
    return 0
}

fun main(args: Array<String>) {
    val array = readLine()!!.split(" ")
    val stack = Stack<String>(array.size)

    array.forEach { item ->
        if (isNumber(item)) {
            stack.push(item)
        } else {
            val secondNumber = stack.pop()
            val firstNumber = stack.pop()
            val result = calc(firstNumber.toInt(), secondNumber.toInt(), item)
            stack.push(result.toString())
        }
    }
    println(stack.pop())
}
