fun main(args: Array<String>) {
    val n = readInputLine().toCharArray()
    
    var nineOtherFind = false
    
    for (i in 1..n.size - 1) {
        if (!nineOtherFind && n[i] != '9') {
            nineOtherFind = true
            n[i - 1]--
        }
        if (nineOtherFind) {
            n[i] = '9'
        }
    }
    println(n.map { it.toString().toInt() }.sum())
}

fun readInputLine(): String {
    return readLine()!!
}
