factorial_L = [1] * 101
for i in range(2, 101):
    factorial_L[i] = factorial_L[i-1] * i

def permutations_count(n, r):
    return factorial_L[n] // factorial_L[n - r]


N_str = input()
N_int = int(N_str)
K = int(input())  # 1, 2, 3
ans = 0
keta = len(N_str)

S_keta = [[0] * (keta+1) for _ in range(K+1)]
for k in range(1, K+1):
    for i in range(1, keta+1):
        S_keta[k][i] = (permutations_count(i, k) // factorial_L[k]) * (9 ** (k))
        # if S_keta[k][i] == 0:
        #     S_keta[k][i] = 1



def solve(nketa, k):
    if k == 1 and nketa == 1:
        return int(N_str[-1])
    if k == 2 and nketa == 2:
        last_2 = int(N_str[-2])
        if last_2 == 0:
            return 0
        return int(last_2-1) * 9 + int(N_str[-1])
    if nketa < k:
        return 0
    if nketa == 0:
        return 0
    ret = 0
    ret += S_keta[k][nketa-1]
    # ret += ( int(N_str[keta-nketa])) * solve(nketa-1, k-1)
    if k-1 == 0:
        ret += int(N_str[keta-nketa])
    else:
        ret += (int(N_str[keta-nketa]) -1) * S_keta[k-1][nketa-1]
        ret += solve(nketa-1, k-1)
    return ret
print(solve(keta, K))