"use strict"

const main = (input) => {
  const lines = input.split("\n")
  if (lines[0].length === 1) {
    console.log(lines[0])
    return
  }
  const len9 = lines[0].length - 1
  const all9 = ((line) => {
    for (let i=1; i<line.length; i++) {
      if (line[i] != '9') {
        return false
      }
    }
    return true
  })(lines[0])
  const head = parseInt(lines[0][0]) - 1
  if (all9) {
    console.log(head + 1 + len9 * 9);
    return
  }
  console.log(head + len9 * 9)
}

main (require('fs').readFileSync('/dev/stdin', 'utf8'))