fun cToI(c: Char): Int {
  return c - '0'
}

fun main(args: Array<String>) {
  val s = readLine()!!
  val n = s.length
  val x1 = s.map(::cToI).sum()
  val x2 = cToI(s[0]) - 1 + 9 * (n - 1)
  println(Math.max(x1, x2))
}
