void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  auto n=readln.chomp.to!(char[]);
  int sum1=0;
  foreach(c; n) sum1+=(c-'0');
  if(n.length>1){
    int tmp=(n[0]-'0')-1;
    tmp+=(n.length.to!(int)-1)*9;
    sum1=max(sum1, tmp);
  }

  writeln(sum1);  
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}