process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
    const list = lines[0].split("").map(v=>v-0);
    let sum = list.reduce((a,b)=>a+b, 0);
    let ans = sum;
    let cur = 0;
    list.forEach((v, i)=>{
        ans = Math.max(ans, cur + v-1 + (list.length-i-1) * 9)
        cur += v;
        
    })
    console.log(ans);
});
