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



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

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

auto solve( 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 );
	
	// dp[ i桁目 ][ i桁目までのゼロ以外の個数 ][ n未満フラグ ] = パターン数
	auto dp = new long[][][]( n.length, 1 + k, 2 );
	dp[ 0 ][ 0 ][ 1 ] = 1;
	dp[ 0 ][ 1 ][ 0 ] = 1;
	dp[ 0 ][ 1 ][ 1 ] = n[ 0 ] - 1;
	foreach( i, d; n[ 1 .. $ ] )
	{
		foreach( j; 0L .. dp[ i ].length.signed )
		{
			// 同値⇒同値
			auto jj = j + ( 0 < d );
			if( jj < dp[ i ].length ) dp[ i + 1 ][ jj ][ 0 ] += dp[ i ][ j ][ 0 ];
			
			// 同値⇒未満
			if( 0 < d )
			{
				dp[ i + 1 ][ j ][ 1 ] += dp[ i ][ j ][ 0 ];														// 0
				if( j + 1 < dp[ i ].length ) dp[ i + 1 ][ j + 1 ][ 1 ] += dp[ i ][ j ][ 0 ] * ( d - 1 );		// [1,d)
			}
			
			// 未満⇒未満
			dp[ i + 1 ][ j ][ 1 ] += dp[ i ][ j ][ 1 ];												// 0
			if( j + 1 < dp[ i ].length ) dp[ i + 1 ][ j + 1 ][ 1 ] += dp[ i ][ j ][ 1 ] * 9;		// [1,10)
		}
	}
	return dp[ $ - 1 ][ $ - 1 ].sum;
}
