def nC2(n):
    return n*(n-1)/2

def nC3(n):
    return n*(n-1)*(n-2)/2/3

def K1(s):
    while s[0]=="0" and len(s)>0:
        s=s[1:]

    ll=len(s)

    if ll==1 or ll ==0:
        N=int(s[0])
    
    elif ll>1:
        N=int(s[0])+9*(ll-1)

    return N


def K2(s):
    while s[0]=="0" and len(s)>0:
        s=s[1:]
    
    ll=len(s)

    if ll==1 or ll ==0:
        N=0
    elif ll==2:
        N=(int(s[0])-1)*9+int(s[1])
    else:
        N=K1(s[1:])+(int(s[0])-1)*(ll-1)*9+9*9*nC2(ll-1)

    return N


def K3(s):
    ll=len(s)

    if ll ==1 or ll==2:
        N=0
    elif ll==3:
        N=(int(s[0])-1)*9*9+int(s[1])*int(s[2])
    else:
        N=K2(s[1:])+(int(s[0])-1)*nC2(ll-1)*9*9+nC3(ll-1)*9*9*9
    
    return N

N=input()
K=input()

if K=="1":
    ans=K1(N)
elif K=="2":
    ans=K2(N)
elif K=="3":
    ans=K3(N)

print(int(ans))
