import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    auto n = sread();
    long sum_n;
    foreach (i; 0 .. n.length)
    {
        // writeln(n[i] - '0');
        sum_n += (n[i] - '0');

    }
    // writeln('s', sum_n);
    // writeln(n.length);
    auto nn = n.to!long();
    // writeln(nn);
    auto tmp = new long[](n.length);
    tmp[0] = nn / (10 ^^ ((n.length) - 1)) - 1;
    foreach (i; 1 .. (n.length))
    {
        tmp[i] = 9;
    }
    // writeln(tmp);
    writeln(max(tmp.sum(), sum_n));

}

auto func(long n)
{
    long sum_x;
    while (n > 0)
    {
        sum_x += n % 10;
        n /= 10;
    }
    return sum_x;
}

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