import itertools
#nCr
import math
def com(n, r):
    if n<r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n=input()
k=int(input())
m=len(n)
if k==1:
    x=int(n[0])
    print(9*(m-1)+x)
    exit()
ans=0
x=int(n[0])
ans+=9**k*com(m-1,k)+(x-1)*com(m-1,k-1)*9**(k-1)
# print(9**k*com(m-1,k),(x-1)*com(m-1,k-1)*9**(k-1))
i=1
while i<m and n[i]=="0":
    i+=1
if k==3:
    if m<3:
        print(0)
        exit()
    if i==1:
        x=int(n[1])
        ans+=9**2*com(m-2,2)+(x-1)*com(m-2,1)*9
        ans+=int(n[2])+9*(m-3)
    if i==2:
        if m>=4:
            x=int(n[2])
            ans+=9**2*com(m-3,2)+(x-1)*com(m-3,1)*9
            ans+=int(n[2])+9*(m-4)+1
elif k==2:
    if m==1:
        print(0)
        exit()
    if i==1:
        ans+=int(n[1])+9*(m-2)
print(ans)