import scala.io.{StdIn => in}

object Main extends App {
  val n = in.readLine
  val digit = n.size
  val res = {
    if(n.tail.forall(_ == '9')) n
    else if(n.head == '1') Array.fill(digit-1)(9).mkString
    else (n.head.toString.toInt - 1) + Array.fill(digit-1)(9).mkString
  }
  // println(res)
  val ans = res.map(_.toString.toLong).reduce(_+_)
  println(ans)
}