fun main(arr: Array<String>) {
    val n = readLine()!!
    if(n.length == 1) {
        println(n)
        return
    }
    if(n.all { it == '9' }) {
        println(9*n.length)
        return
    }
    if(n.drop(1).all { it == '9' }) {
        println(n.map { it.toString().toInt() }.sum())
        return
    }
    val tmp = 9 * (n.length-1) + (n[0].toString().toInt() - 1)
    println(tmp)
}

