import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] xs) {

    int ans = xs.sum;
    for (int i = 0; i < xs.length; i++) {
        auto buf = xs.dup;
        if (buf[i] > 0) {
            buf[i]--;
            for (int j = i + 1; j < buf.length; j++) {
                buf[j] = 9;
            }

            ans = max(ans, buf.sum);
        }
    }

    return ans;
}

void main() {
    auto s = readln.chomp;
    auto xs = s.map!(e => cast(int)(e - '0')).array;

    auto ans = calc(xs);
    writeln(ans);
}