//300
fun a021(args: Array<String>) {
    val nStr = args[0]
    val nLong = nStr.toLong()
    var ans = 0L
    fun pow(x: Int, n: Int): Long = Math.pow(x.toDouble(), n.toDouble()).toLong()
    for (digit in 1..17) {
        ans += nLong % pow(10, digit) / pow(10, digit - 1)
    }
    println(Math.max(9L * (nStr.length - 1) + nStr[0].toString().toLong() - 1, ans))
}

fun main(args: Array<String>) {
    a021(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}