import java.util.Scanner

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextLong()
    var ans = dsum(n)
    for (j in (1..16)) {
        var k = n
        for (i in (1..j)) { k /= 10 }
        for (i in (1..j)) { k *= 10 }
        val l = dsum(k - 1)
        if (l >= ans) ans = l
    }
    println(ans)
}

fun dsum(n: Long): Long {
    if (n <= 0) return 0
    if (n <= 9) return n
    return dsum(n / 10) + n % 10
}