import itertools
import sys

def cmb(n, r):
	if n - r < r: r = n - r
	if r == 0: return 1
	if r == 1: return n
	if r < 0: return 0

	numerator = [n - r + k + 1 for k in range(r)]
	denominator = [k + 1 for k in range(r)]

	for p in range(2,r+1):
		pivot = denominator[p - 1]
		if pivot > 1:
			offset = (n - r) % p
			for k in range(p-1,r,p):
				numerator[k - offset] /= pivot
				denominator[k] /= pivot

	result = 1
	for k in range(r):
		if numerator[k] > 1:
			result *= int(numerator[k])

	return result

n = input()
k = int(input())
l = len(n)

if l < k:
	print(0)
	sys.exit()
elif l == 1 and k == 1:
	print(n)
	sys.exit()

#dp[i][j] = i桁目までで、0でない数字がちょうどj個あるようなものの個数
dp = [[0 for _ in range(4)]for _ in range(l+1)]
dp[1][0] = 1

for i in range(1,l+1):
	for j in range(4):
		if i >= j:
			dp[i][j] = cmb(i,j) * (9**j)

ans = dp[l-1][k]
ans += (int(n[0]) - 1) * dp[l-1][k-1]

num = l
for i in range(1,l):
	if n[i] != '0':
		num = i
		break
if num == l:
	if n.count('0') == l-k:
		print(ans+1)
	else:
		print(ans)
	sys.exit()

tmp1 = (int(n[num])-1) * cmb(9,k-2)
tmp2 = 9**(k-1)

for v in itertools.combinations(range(num,l), k-1):
	if num in v:
		if len(v) == 2:
			t = int(n[v[i]])
		else:
			t = 1
		ans += tmp1 + t
	else:
		ans += tmp2

print(ans)
