function Main(input) {
    var N = input;
    var length = N.length;
    if(length % 2 == 0){
        console.log((length - 1) * 9) 
    }else{
        var _N = N;
        var a = (length - 2) * 9
        var b = _N.slice(1);
        console.log(parseInt(b,10) + a + 1);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));