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

l = len(str(n))

if l < k:
    t = 0
elif k == 1:
    r = int(str(n)[0])
    t = 9*(l-1)+r
elif k == 2:
    r, s = int(str(n)[0]), int(str(n)[1])
    t = 81*(l-1)*(l-2)//2 + 9*(r-1)*(l-1) + s + 9*(l-2)
else:
    r, s, u = int(str(n)[0]), int(str(n)[1]), int(str(n)[2])
    t = 729*(l-1)*(l-2)*(l-3)//6 + 81*(r-1)*(l-1)*(l-2)//2 + 81*(l-2)*(l-3)//2 + 9*(s-1)*(l-2) + 9*(l-3) + u
print(t)
