object Main extends App {
  @scala.annotation.tailrec
  def loop(chars: Seq[Char], acc: Seq[Char]): Int = chars match {
    case Seq() => acc.map(i => new String(Array(i)).toInt).sum
    case x :: xs if x == 9 => loop(xs, acc :+ x)
    case xs => xs.length * 9 + acc.map(i => new String(Array(i)).toInt).sum - 1
  }
  val sc = new java.util.Scanner(System.in)
  val x::xs = sc.next().toCharArray.toList
  println(if (xs.isEmpty) x.toString else loop(xs, Seq(x)))
}
