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

keta = len(n)
ans = 0
if k == 1:
    ans += 9 * (keta-1) + int(n[0])
    
if k == 2:
    ans +=int(n[0])*9*(keta-1) - (9-int(n[1]))*(keta-1) + 81*(keta-2)*(keta-1)/2

if k == 3:
    if keta < 3:
        ans = 0
    else:
        ans += int(n[0])*81*(keta-1)*(keta-2)/2 - (10-int(n[1]))*9 + (int(n[2]))
        for i in range(keta-2):
            ans += 729*(keta-i-2)*(keta-i-3)/2



print(int(ans))