from math import factorial
def combi(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

def main():
	import sys
	input = sys.stdin.readline
	N = int(input())
	K = int(input())
	dig = len(str(N))
	ans = 0
	if K == 1:
		ans = 9 * (dig - 1) + int(str(N)[0])
	elif K == 2:
		if dig < K:
			ans = 0
		elif dig == K:
			ans = (int(str(N)[0]) - 1) * 9 + int(str(N)[1])
		else:
			a1 = (9 ** K) * combi(dig-1, K) # 0***
			a2 = (int(str(N)[0])-1) * (9 ** (K-1)) * combi(dig-1, K-1)
			a3 = 9 * combi(dig-2, K-1)
			a4 = int(str(N)[1]) * combi(dig-2, K-2)
			ans = a1 + a2 + a3 + a4
	else:
		if dig < K:
			ans = 0
		elif dig == K:
			a1 = (int(str(N)[0])-1) * (9 ** 2)
			a2 = (int(str(N)[1])-1) * 9
			a3 = int(str(N)[2])
			ans = a1 + a2 + a3
		else:
			a1 = (9 ** K) * combi(dig-1, K) # 0***
			a2 = (int(str(N)[0])-1) * (9 ** (K-1)) * combi(dig-1, K-1)
			a3 = (9 ** (K-1)) * combi(dig-2, K-1)
			a4 = (int(str(N)[1]) - 1) * 9 * combi(dig-2, K-2)
			a5 = 9 * (dig-3)
			a6 = int(str(N)[2])
			ans = a1 + a2 + a3 + a4 + a5 + a6

	print(ans)


if __name__ == '__main__':
    main()