import math

x = int(input())
K = int(input())

N = str(x)
n = len(N)

keta = [0] * n


def com(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


for i in range(n):
    if int(N[i]) == 0:
        keta[i] = 0
    else:
        keta[i] = int(N[i])

Sum = 0

if K == 1:
    Sum += keta[0]
    Sum += 9 * (n - 1)

elif K == 2:
    for j in range(1, n):
        if j == 1:
            Sum += ((keta[0] - 1) * 9) + keta[j]
        else:
            Sum += ((keta[0] - 1) * 9) + 9

    Sum += 81 * com(n - 1, 2)

elif K == 3:
    for j in range(1, n - 1):
        for k in range(j + 1, n):
            if j == 1:
                #a = Sum
                if k == 2:
                    Sum += ((keta[0] - 1) * 81) + ((keta[j] - 1) * 9) + keta[2]
                else:
                    Sum += ((keta[0] - 1) * 81) + ((keta[j] - 1) * 9) + 9
                #print(Sum - a)
            else:
                Sum += ((keta[0] - 1) * 81) +((keta[j] - 1) * 9) + keta[k]

    Sum += (9**3) * com(n - 1, 3)

print(Sum)
