import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.next()
    var flg = 0

    for (i in 0 until n.length) {
        if (i != 0 && n[i] != '9') {
            flg = 1
        }
    }
    println((n[0] + "").toInt() + 9 * (n.length - 1) - flg)
}
