N = input()
K = input()
A = len(N)
NOB = True
if A == 1 and (K == '2' or K == '3'):
	print(0)
elif K == '1':
	print(9*(A-1)+ord(N[0])-ord('0'))
elif K == '2':
	for i in range(1,A):
		if N[i] != '0':
			NOB = False
			break
	print((81*(A-1)*(A-2))//2 + (ord(N[0])-ord('1'))*9*(A-1) + ord(N[i])- ord('0') + 9*(A-1-i))
else:
	for i in range(1,A):
		if N[i] != '0':
			NOB = False
			break
	print(((A-1)*(A-2)*(A-3)*729)//6 + ((ord(N[0])-ord('1'))*81*(A-1)*(A-2))//2 + (ord(N[i])-ord('1'))*(A-i-1)*9 + (((A-1-i)*(A-2-i))//2)*81 + (A-i-1)*9)