import std.stdio,
       std.string,
       std.conv;

void main() {
  string N = readln.chomp;
  int a, b;
  
  foreach (c; N) {
    a += c - '0';
  }

  b = N[0] - 1 - '0';
  foreach (c; N[1..N.length]) {
    b += '9' - '0';
  }

  writeln(a > b ? a : b);
}
