N = int(input())
K = int(input())
n = str(N)
l = len(n)
m = int(n[0])
if K == 1:
    if l == 1:ans = N
    else:ans = 9*(l-1)+m
elif K == 2:
    if l < 2:ans = 0
    elif l == 2:ans = (m-1)*9+int(n[-1])
    else:ans = 9*(l-1)*9*(l-2)//2+(m-1)*(l-1)*9+1+(l-2)*9
else:
    if l < 3:ans = 0
    elif l == 3:ans = (m-1)*9*9+int(n[1])*int(n[2])
    else:ans = 9*9*9*(l-1)*(l-2)*(l-3)//6+(m-1)*9*9*(l-1)*(l-2)//2+int(n[1])*int(n[2])+9*9*(l-3)*(l-4)//2+(int(n[1])+int(n[2]))*9*(l-3)
print(ans)
