function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	input = input.trim().split("").map((a)=>Number(a));
	//input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  var output = 0;
  var flag = true;
  
  for(var i = 0; i < input.length - 1; i++){
    var mae = input[i];
    var ato = input[i+1];
    if(!flag){
       output += 9;
       continue;
    }
    if(ato != 9){
       output += mae - 1;
       output += 9;
       flag = false;//以降、全て+9
    }else{
      output += 9;
    }
  }
  myout(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
