fun main(args: Array<String>) {
    val s = readLine()!!
    val n = s.length

    if (s == s[0] + "9".repeat(n - 1)) {
        println(s[0] - '0' + 9 * (n - 1))
    } else {
        println(s[0] - '1' + 9 * (n - 1))
    }
}