function Main(input){
	var N = input.trim();
	var l = N.length - 1;
	var lt = parseInt(N.substr(0,1));
	var rt = N.substr(1).match(/9/g);
	var ans;
	if(rt) rt = rt.length;
	else rt = -1;
	
	if(l === 0)ans = parseInt(N);
	else if(rt === l) ans = l * 9 + lt;
	else ans = l * 9 + lt - 1;
	
	console.log(ans);
}

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