def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


n=int(input())
k=int(input())
l=len(str(n))

def zero(n,k,l):
    saidai=n//(10**(l-1))
    small=n-10**(l-1)*saidai
    if l<k:
        return 0
    elif k==0:
        return 1
    elif l==1:
        return n
    elif l==k:
        return (cmb(l-1,k-1)*9**(k-1)*(saidai-1)+zero(small,k-1,l-1))
    else:
        ans = cmb(l-1,k)*9**k+cmb(l-1,k-1)*9**(k-1)*(saidai-1)+zero(small,k-1,l-1)
        return ans


print(zero(n,k,l))
