import math
n=input()
k=int(input())
if len(n)>=3:
    x=int(n[0]+n[1]+n[2])
if len(n)>=2:
    y=int(n[0]+n[1])
z=int(n[0])

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

# k==1のもの数える
if k==1:
    print(z*len(n)+(9-z)*(len(n)-1))

elif k==2 and len(n)>=2:
    a=0
    for i in range(1,10):
        for j in range(1,10):
            if int(str(i)+str(j))<=y:
                a+=1
            else:
                break

    v=combinations_count(len(n),2)
    if len(n)>=3:
        w=combinations_count(len(n)-1,2)
        w1=(9-int(n[1]))*(len(n)-2)
        print(a*v+(81-a)*w+w1)
    else:
        print(a*v)
        exit()

elif k==3 and len(n)>=3:
    a=0
    for i in range(1,10):
        for j in range(1,10):
            for k in range(1,10):
                if int(str(i)+str(j)+str(k))<=x:
                    a+=1

    v=combinations_count(len(n),3)
    if len(n)>=4:
        w=combinations_count(len(n)-1,3)
        if int(n[2])!=0:
            w1=combinations_count(len(n)-1,2)*(9-int(n[2]))
            w2 = combinations_count(len(n) - 2, 2) * (81 - (int(n[1]) * int(n[2])))
        else:
            w1=0
            w2 = combinations_count(len(n) - 2, 2) * (81 - (int(n[1])))
        print(a*v+(729-a)*w+w1+w2)
    else:
        print(a*v)
        exit()
else:
    print(0)