N = int(input())
K = int(input())

def comb(n,k):
	if k==0: return 1
	if k==1: return n
	if k==2: return n*(n-1)//2
	return n*(n-1)*(n-3)//2 # b/c K<=3

def f(N,K):
	if N==0: return 0
	strN	= str(N)
	top		= int(strN[0])
	digit	= len(strN)

	if K==1: return top-1

	result  = comb(digit-1, K-1) * (9**(K-1)) * (top-1)
	result += f(N - top*(10**digit), K-1)
	return result


print(f(N,K))