n = int(input())
k = int(input())
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

count = 0
for i in range(1,len(str(n))):
    if i >= k:
        count += 9*comb(i-1,k-1)*(9**(k-1))
        

if k == 1:
    count += int(str(n)[0])
    print(count)
    exit()
if k == 2:
    count += (int(str(n)[0])-1)*9*(len(str(n))-1)
    
    count2 = 0
    for i in range(1,len(str(n))-1):
        if i >= 1:
            count2 += 9*comb(i-1,0)*(9**(0))
    count += int(str(n)[1])    
    print(count+count2)
    exit()

if k == 3:
    count += (int(str(n)[0])-1)*comb(len(str(n))-1,2)*81
    for i in range(1,len(str(n))-1):
        if i >= 2:
            count += 9*comb(i-1,2-1)*(9**(2-1))
    count += (int(str(n)[1])-1)*9*(len(str(n))-2)
    
    count2 = 0
    for i in range(1,len(str(n))-2):
        if i >= 1:
            count2 += 9*comb(i-1,0)*(9**(0))
    count += int(str(n)[2])    
    print(count+count2)
    exit()
        


    