N = int(input())
K = int(input())
n = N - 1
l = len(str(n))
cnt = 0


def cng(s):
    x = list(str(N))
    c = 0
    for i in x:
        if int(i) != 0:
            c += 1
    return s == c


if K == 1:
    if N < 1:
        cnt = 0
    else:
        cnt = 9 * (l - 1) + n // (10 ** (l - 1))
    if cng(1):
        cnt += 1
elif K == 2:
    if N < 11:
        cnt = 0
    else:
        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
    if cng(2):
        cnt += 1
else:
    if N < 111:
        cnt = 0
    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)
    if cng(3):
        cnt += 1

print(cnt)
