from itertools import combinations

n = int(input())
k = int(input())
ans = 0
if k == 1:
	for i in range(1, 101):
		m = n//(10**i)
		if m == 0:
			ans += n//(10**(i-1))
			break
		else:
			ans += 9
	print(ans)

elif k == 2:
	if n < 10:
		print(0)
	elif n < 100:
		p = n//10
		q = (n-10*p)
		print(9*(p-1)+q)
	else:
		ans += 81
		for i in range(3, 101):
			m = n//(10**i)
			if m == 0:
				p = n//(10**(i-1))
				ans += 9*(p-1)*(i-1)
				q = n - p*(10**(i-1))
				for j in range(i-2, -1, -1):
					r = q//(10**j)
					if r != 0:
						ans += (r + j*9)
						break
					else:
						q -= r*(10**j)
				break
			else:
				ans += (i-1) * 81
		print(ans)

else:
	if n < 100:
		print(0)
	elif n < 1000:
		p = n//100
		q = (n-100*p)
		r = q//10
		print(81*(p-1)+9*(q-1)+r)
	else:
		ans += 729
		for i in range(4, 101):
			m = n//(10**i)
			if m == 0:
				p = n//(10**(i-1))
				ans += (p-1)*81*(i-1)*(i-2)//2
				q = n - p*(10**(i-1))
				for j in range(i-2, 0, -1):
					r = q//(10**j)
					if r == 0:
						continue
					else:
						ans += (81*j*(j-1)//2 + 9*j*(r-1))
						q -= r * (10**j)
						l = j-1
						while (l+1):
							th = q//(10**l)
							if th == 0:
								l -= 1
							else:
								ans += th + 9*l
								break
						break
			else:
				ans += (729 * (i-1) * (i-2)) //2
		print(ans)