import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math, core.stdc.stdio;
int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.to!(int[]); }

int f(string n) {
    int k = n.length.to!int;
    int r = (n[0] - '0') + (k - 1) * 9;
    if (count(n[1..$], '9') != k - 1) r--;
    return r;
}

void main() {
    writeln(readln.strip.f);
    auto _ = readln(); // dbg
}