object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.next()
  if (n.tail.forall(_ == '9')) {
    println(n.toList.map(_.asDigit).sum)
  } else {
    println((n.head.asDigit - 1) + (9 * (n.length - 1)))
  }
}
