object Main extends App {
	import scala.math._

	val n = scala.io.StdIn.readLong
	val a = log10(n).toInt

	var test = 1L

	for(i<-0 until a){
		test = test * 10L
	}

	var ans = (n/test - 1)

	for(i<-0 until a){
		ans = ans + 9L
	}

	println(ans)


}
