unittest
{
	assert( [ "100" ].parse.expand.solve == 18 );
	assert( [ "9995" ].parse.expand.solve == 35 );
	assert( [ "3141592653589793" ].parse.expand.solve == 137 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto ns = input.front.map!( ( a ) => a.to!long - '0' ).array;
	return tuple( ns );
}

auto solve( long[] ns )
{
	auto d = false;
	auto ans = 0L;
	foreach_reverse( i, n; ns )
	{
		if( 0 < n && d )
		{
			n--;
			ans = 9 * ( ns.length.signed - i - 1 );
		}
		if( n < 9 ) d = true;
		ans += n;
	}
	return ans;
}
