import sys
n = int(input())
k = int(input())
keta = len(str(n))
from math import factorial
al = (factorial(keta) / factorial(k) / factorial(keta - k)) * 81
diff = 0
if k == 2:
    diff += (9-int(str(n)[0]))*9*(keta-1)
    diff += 9-int(str(n)[1])
elif k == 3:
    c = (factorial(keta-1) / factorial(k) / factorial(keta-1 - k))
    diff += (9-int(str(n)[0]))*81*c
    c = (factorial(keta-2) / factorial(k) / factorial(keta-2 - k))
    diff += (9-int(str(n)[1]))*9*c
    diff += 9-int(str(n)[2])
elif k == 1:
    diff += 9-int(str(n)[0])
al = (factorial(keta) / factorial(k) / factorial(keta - k)) * (9**k)
print(int(al-diff))