N_str = input().strip()
L = len(N_str)
N_list = list(map(int, N_str))
N = int(N_str)
K = int(input())

def count1(s):
	if N_list[s] == 0:
		if s < L - 1:
			return count2(s + 1)
		else:
			return 0
	total = 0
	for i in range(s, L):
		if i == s:
			total += N_list[i]
		else:
			total += 9
	return total

def count2(s):
	if N_list[s] == 0:
		if s < L - 1:
			return count2(s + 1)
		else:
			return 0
	total = 0
	for i in range(s, L - 1):
		if i == s:
			if N_list[i] > 0:
				total += (N_list[i] - 1) * (L - i - 1) * 9
			total += count1(i + 1)
		else:
			total += 81 * (L - i - 1)
	return total

if K == 1:
	total = count1(0)
elif K == 2:
	total = count2(0)
else:
	total = 0
	for i in range(0, L - 2):
		if i == 0:
			if N_list[i] > 0:
				total += (N_list[i] - 1) * (L - i - 1) * 9 * (L - i - 2) * 9 // 2
			total += count2(i + 1)
		else:
			total += 729 * (L - i - 1) * (L - i - 2) // 2

print(total)
