from math import factorial
N = int(input())
K = int(input())


def n_C_k(n, k):
    factorial_n = factorial(n)
    factorial_k = factorial(k)
    factorial_nk = factorial(n-k)
    return factorial_n//(factorial_k*factorial_nk)

def solve(N, k):
    #ls = list(str(N))
    n = str(N)
    keta = len(n)

    if k == 0:
        return 0

    t = n[0]
    s = ""

    for i in range(keta-1):
        t += "0"
    for i in range(keta-1):
        s += n[i+1]
    return solve2(t, k) + solve(s, k-1)

def solve2(t, k):
    n = str(t)
    keta = len(n)
    #print(keta, )
    if k == 1:
        print(t, k)
        print((keta-1)*9+int(n[0]))
        return (keta-1)*9+int(n[0])
    if k == 2:
        out = 0
        out += (int(n[0])-1)*(keta-1)*9 #最上桁を使う場合
        #print(out, 5555)
        if keta-1 >= 2:
            out += n_C_k(keta-1, 2)*9*9  # 最上桁を使わない場合
        print(t, k)
        print(out)
        return out
    else:
        out = 0
        if keta-1 >= 2:
            out += (int(n[0])-1)*n_C_k(keta-1, 2)*9*9
        if keta-1 >= 3:
            out += n_C_k(keta-1, 3)*9*9*9
        return out

    
ans = solve(N, K)
print(ans)