N=int(input())
K=int(input())

n=str(N)
n_digi=len(n)

import math

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)


if n_digi < K:
    print(0)

else:
    ans=0
    
    if n_digi>K:
        ans += permutations_count(n_digi-1,K)*9
    
    keta1=int(n[0])
    nokori=n[1:]
    
    if keta1 != 1 and K!=1:
        ans += (keta1-1)*ermutations_count(n_digi-2,K-1)*9
        
    elif keta1 != 1 and K==1:
        ans += (keta1-1)
        
    elif K==1 and int(nokori)==0:
        ans += 1
        
    else:
        noko_list = list(nokori)
        aa=1
        bb=sum(noko_list)
        for j in noko_list:
            aa *=j
             
        ans += aa-bb*(K-1)
        
            
        


