fun main(args: Array<String>){
    var n = readLine()!!
    val topDigit = n[0].toString().toInt()
    n = n.slice(1 until n.length)
    var maxDigit = 0
    var minDigit = 9
    n.forEach {
        maxDigit = Math.max(maxDigit, it.toString().toInt())
        minDigit = Math.min(minDigit, it.toString().toInt())
    }
    println(
        if (minDigit == 9) topDigit + (9 * n.length)
        else (topDigit - 1) + (9 * n.length)
    )
}
