n = int(input())
k = int(input())

l = [[0,0,0]]
p1 = 0
p2 = 0
p3 = 0

for i in range(1, 1000):
    m = len(str(i)) - str(i).count("0")
    if m == 3:
        p3 += 1
    elif m == 2:
        p2 += 1
    else:
        p1 += 1
    l.append([p1,p2,p3])
if n <= 999:
    ans = l[n][k-1]

else:
    l2 = [l[9], l[99], l[999]]
    sn = str(n)
    keta = len(sn)
    a = int(sn[0])
    a2 = int(sn[1])
    a3 = int(sn[2])
    a4 = int(sn[3])
    for i in range(keta - 4):
        p1 = l2[-1][0] + 9
        p2 = l2[-1][1] + 9 * l2[-1][0]
        p3 = l2[-1][2] + 9 * l2[-1][1]
        l2.append([p1,p2,p3])
    if k == 1:
        ans = l2[-1][0] + a
    elif k == 2:
        ans = l2[-1][1] + (a - 1)* l2[-1][0] + l2[-2][0] + a2
    else:
        if a2 != 0:
            ans = l2[-1][2] + (a - 1)* l2[-1][1] + l2[-2][1] + (a2 - 1)* l2[-2][0] + l2[-3][0] + a3
        else:
            ans = l2[-1][2] + (a - 1)* l2[-1][1] + l2[-3][1] + (a3 - 1)* l2[-3][0] + l2[-4][0] + a4
print(ans)