N = input()
K = int(input())
def comb(a, b):
    if b == 1:
        return a
    if b == 2:
        return a*(a-1)//2
    if b == 3:
        return a*(a-1)*(a-2)//6
ans = 0
for k in range(K):
    n = N[k:]
    L = len(n)
    s = K-k
    ans += comb(L-1,s)*(9**s)
    if s-1 > 0:
        ans += (int(N[0])-1)*comb(L-1,s-1)*(9**(s-1))
ans += int(N[K-1])
print(ans)