import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
k = int(input())
l = len(str(n))
a = n//(10**(l-1))
b1 = 0
b2 = 0
c1 = 0
c2 = 0
c = 0
x =0
y =0
if k == 1:
    c = 9*(l-1) + a
    print(c)

elif k == 2:
    for i in range(1,l):
        if n%(10**(l-i)) >= 10**(l-i-1):
            b1 = l - i - 1
            b2 = (n%(10**(l-i)))//(10**(l-i-1))
            break
    c = 81*(l-1)*(l-2)//2 + (a-1)*9*(l-1) + b2 + b1*9
    print(c)

else:
    for i in range(1,l):
        if n%(10**(l-i)) >= 10**(l-i-1):
            b1 = l - i - 1
            b2 = (n%(10**(l-i)))//(10**(l-i-1))
            x = i
            break
    for i in range(x+1,l):
        if n%(10**(l-i)) >= 10**(l-i-1):
            c1 = l - i - 2
            c2 = (n%(10**(l-i)))//(10**(l-i-1))
            
            break        
    for i in range(2,l-1):
        y += comb(i,2)
    c = 729*y + (a-1)*729*comb(l-1,2) + 81*comb(b1,2) + (b2-1)*b1*9 +c1*9 +c2
    print(c)