N = int(input())
K = int(input())

mm1 = [0,0,0,0]
mm2 = [0,0,0,0]
mm3 = [1,0,0,0,0]

lgt = len(str(N))

for i in range(1,lgt):
    for j in range(3):
        mm1[j+1] = mm2[j]*9
        mm1[j] += mm2[j]
        mm1[0] = mm2[0]

    for k in range(10):
        mm = list(str(N))
        if k < int(mm[i]) and k != 0:
            mm1[3] += mm3[2]
            mm1[2] += mm3[1]
            mm1[1] += mm3[0]
        elif k < int(mm[i]) and k == 0:
            mm1[3] += mm3[3]
            mm1[2] += mm3[2]
            mm1[1] += mm3[1]
            mm1[0] += mm3[0]
        elif k==int(mm[i]) and k!=0:
            for l in range(4):
                if mm3[l] == 1:
                    mm3[l+1] = 1
                    mm3[l] = 0 
                    break
    # print(mm1,mm3)
    mm2 = mm1.copy()

print(mm2[K]+mm3[K])


