import math

n = int(input())
k = int(input())

digit_num = math.floor(math.log10(n)) + 1
count = [0 for _ in range(n)]
# 1桁少ないとこまで
for i in range(digit_num-1):
    j = i + 1
    if j > k:
        temp = ((j*j + 3*j + 2) * 9^(j-2))  /2
        count[i] = temp

b = 0

for i in range(digit_num,k,-1):
    s = int(str(n)[i])
    if s > 1:
        temp = (s-1) * count[i+1]
        b = b + temp

ans = sum(count)+b

print(b)