n = int (input ())
k = int (input ())
if k == 1:
	ans = 0
	i = 0
	while (pow (10, i) <= n):
		l = pow (10, i)
		r = min (10 * l - 1, n)
		ans += (r - l) // pow (10, i) + 1
		i += 1
	print (ans)
elif k == 2:
	ans = 0
	i = 1
	while (pow (10, i) <= n):
		l = pow (10, i)
		r = min (10 * l - 1, n)
		ans += ((r - l) // pow (10, i) + 1) * 9 * i 
		tmp = (r - l) // pow (10, i - 1)
		a = tmp % 10
		ans -= (9 - a) 
		i += 1
	print (ans)
else:
	ans = 0
	i = 2
	while (pow (10, i) <= n):
		l = pow (10, i)
		r = min (10 * l - 1, n)
		ans += ((r - l) // pow (10, i) + 1) * 9 * 9 * i * (i - 1) // 2
		tmp = (r - l) // pow (10, i - 2)
		a = tmp % 100 // 10
		b = tmp % 10 
		ans -= (9 - a) * 9 + (9 - b)
		i += 1
		# print (l, r, ans)
	print (ans)