N = int(input())
K = int(input())
l = len(str(N))
cnt = 0
if K > l:
    cnt = 0
elif K == 1:
    cnt = 9 * (l - 1) + N // (10 ** (l - 1))
elif K == 2:
    a = int(str(N)[0])
    b = int(str(N)[1])
    cnt = 81 * ((l - 1) * (l - 2) // 2) + 9 * a * (l - 2) + (a - 1) * 9 + b
else:
    a = int(str(N)[0])
    b = int(str(N)[1])
    c = int(str(N)[2])
    cnt = 9 ** 3 * ((l - 1) * (l - 2) * (l - 3) // 6) + a * 9 * 9 * ((l - 2) * (l - 3) // 2) + (a - 1) * 9 * 9 * (l - 2) + (b - 1) * 9 * (l - 2) + 9 * (l - 3) + c

print(cnt)
