from itertools import combinations
N=input()
K=int(input())
L = len(N)
# dp = [[[0]*(L+1) for _ in range(L+1)] for _ in range(2)]
nonzero = [0]*(L+1)
# nonzero[i]: i-1ケタ目までの非ゼロの累積個数
for i in range(1, L+1):
    nonzero[i] = nonzero[i-1] + int(N[i-1] != 0)

if K == 1:
    ans = 0
    for tpl in combinations(range(L), 1):
        d1 = tpl[0]
        if d1 == 0:
            ans += int(N[d1])
        else:
            ans += 9
elif K == 2:
    ans = 0
    for tpl in combinations(range(L), 2):
        d1, d2 = sorted(list(tpl))
        n1 = int(N[d1])
        n2 = int(N[d2])
        if d1 == 0:
            ans += (n1-1)*9
            if nonzero[d2] > 1:
                ans += 9
            else:
                ans += n2
        else:
            ans += 9 * 9

else:
    ans = 0
    for tpl in combinations(range(L), 3):
        d1, d2, d3 = sorted(list(tpl))
        n1 = int(N[d1])
        n2 = int(N[d2])
        n3 = int(N[d3])
        if d1 == 0:
            ans += (n1-1)*9*9
            if nonzero[d2] > 1:
                ans += 9*9
            else:
                if nonzero[d3] == 1:
                    pass
                elif nonzero[d3] == 2:
                    if n2 == 0:
                        pass
                    else:
                        ans += (n2-1)*9 + n3
                else:
                    ans += n2 * 9
        else:
            ans += 9*9*9

print(ans)