unittest
{
	assert( [ "100", "1" ].parse.expand.solve == 19 );
	assert( [ "25", "2" ].parse.expand.solve == 14 );
	assert( [ "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "3" ].parse.expand.solve == 117879300 );
	
	assert( [ "99", "3" ].parse.expand.solve == 0 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.functional;
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 n = input.front.map!( ( a ) => ( a - '0' ).to!( long ) ).array;
	input.popFront;
	auto k = input.front.to!( long );
	return tuple( n, k );
}

auto solve( long[] n, long k )
{
	return memoize!solve2( n, k, true );
}

long solve2( long[] n, long k, bool z )
{
	auto ans = 0L;
	foreach( i; 0L .. n.length.signed )
	{
		if( z )
		{
			if( n[ i ] == 0 ) continue;
			if( k == 1 ) ans += n[ i ];
			else         ans += ( n[ i ] - 1 ) * memoize!solve2( n[ i + 1 .. $ ], k - 1, false ) + memoize!solve2( n[ i + 1 .. $ ], k - 1, true );
		}
		else
		{
			if( k == 1 ) ans += 9;
			else         ans += 9 * memoize!solve2( n[ i + 1 .. $ ], k - 1, false );
		}
		z = false;
	}
	return ans;
}
