def gcd(x, y):
    while(y): 
        x, y = y, x % y 
    return x
def NcR(n, r): 
    p = 1
    k = 1
    if (n - r < r): 
        r = n - r 
  
    if (r != 0):  
        while (r): 
            p *= n 
            k *= r 
            m = gcd(p, k) 
            p //= m 
            k //= m  
            n -= 1
            r -= 1
    else: 
        p = 1
    return p
def f1(n,a1):
    return (a1+9*(n-1))
def f2(n,a1,a2):
    s = 0
    if(n>=3):
        s = NcR(n-1,2) * 9**2
    if(n>=2):
        s+= (n-1) * (9) * (a1-1)
        s+= f1(n-1,a2)
    return s
def f3(n,a1,a2,a3):
    s = 0
    if(n>=4):
        s = NcR(n-1,3) * 9**3
    if(n>=3):
        s+= NcR(n-1,2) * (9**2) * (a1-1)
        s+= f2(n-1,a2,a3)
    return s
n = input()
k = input()
l = len(n)
if(k == '1'):
    print(f1(l,int(n[0])))
elif(k == '2'):
    print(f2(l,int(n[0]),int(n[1])))
else:
    print(f3(l,int(n[0]),int(n[1]), int(n[2])))
    