import scala.io.StdIn

object Main {

  def digitSum(n: String): Int = n.toList.map(_.asDigit).sum

  def main(args: Array[String]): Unit = {
    val N: String = StdIn.readLine.trim
    println(digitSum((N(0).asDigit-1).toString + "9" * (N.length-1)))
  }
}
