import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    auto n = sread();
    // writeln(n);
    long sum_n;
    foreach (i; 0 .. (n.length))
    {
        sum_n += n[i] - '0';
    }
    // writeln(sum_n);
    auto tmp = new long[](n.length);
    auto long_n = n.to!long();
    // writeln(long_n / (10 ^^ ((n.length) - 1)) - 1);
    tmp[0] = long_n / (10 ^^ ((n.length) - 1)) - 1;
    foreach (i; 1 .. (n.length))
    {
        tmp[i] = 9;
    }
    // writeln(tmp);
    // writeln(tmp.sum());
    writeln(max(sum(tmp), sum_n));
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}
