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 - (9 - r)
elif k == 2:
    r, s = int(str(n)[0]), int(str(n)[1])
    t = 81 * l * (l-1) // 2 - 9 * (9-r) * (l-1) - (9-s)
else:
    r, s, u = int(str(n)[0]), int(str(n)[1]), int(str(n)[2])
    t = 729 * l * (l-1) * (l-2) // 6 - 81 * (9-r) * (l-1) * (l-2) // 2 - 9 * (9-s) * (l-2) - (9-u)
print(t)
