import math
n=input()#as string
k=int(input())

e=9**k
f=len(n)
ans=0

zeroexist=True#途中桁に0が存在するかどうか

#kの範囲が極めて狭いので愚直に行く
if k==1:
    for i in range(f):
        if i==0:
            ans+=int(n[i])
        else:
            ans+=e
elif k==2:
    for i in range(f):
        for j in range(i+1,f):
            if i==0:
                ans+=(int(n[i])-1)*9
                if j==1:
                    ans+=int(n[j])
                    if int(n[j])!=0:
                        zeroexist=False
                else:
                    if zeroexist and int(n[j])!=0:
                        zeroexist=False
                    
                    if zeroexist:
                        ans+=int(n[j])
                    else:
                        ans+=9
            else:
                ans+=e
            
else:
    for i in range(f):
        for j in range(i+1,f):
            for k in range(j+1,f):
                if i==0:
                    ans+=(int(n[i])-1)*9*9
                    if j==1:
                        ans+=int(n[j])*9
                        if int(n[j])!=0:
                            zeroexist=False
                    else:
                        if zeroexist and int(n[j])!=0:
                            zeroexist=False
                        
                        if zeroexist:
                            if int(n[j])==0:
                                ans+=int(n[k])
                            else:
                                ans+=(int(n[j])-1)*9+int(n[k])
                        else:
                            ans+=9*9
                else:
                    ans+=e
print(ans)
    