import math

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


def saiki2(N, K, vlen, p):
    a = 0
    if (K == 0):
        ans =  1
    
    elif(N[p] == '0'):
        ans=  saiki2(N, K, vlen, p+1)

    else:
        if(vlen == 1):
            ans = int(N[p])
        else:
            a = saiki2(N, K-1, vlen, p+1)

            b = (int(N[p])-1) * 9**(K-1) * combinations_count(vlen-p-1, K-1)
            if(vlen-p-1 <  K):
                c = 0
            else:
                c =  9**(K) * combinations_count(vlen-p-1, K)
            ans = a+b+c

    return ans

N = input()
Nn = int(N)
K = int(input())
vlen = len(N)

ans = saiki2(N,K,vlen,0)

print(ans)