import math
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

answer=0

n=int(input())
k=int(input())
now=n
keta=0
while now!=0:
    now=now//10
    keta+=1
keta-=1

if k>keta+1:
    print(0)
else:
    moto=10**keta
    first=n//moto
    if k>=2:
        second=(n-first*moto)//(moto//10)
        if k>=3:
            third=(n-first*moto-second*(moto//10))//(moto//100)
    #print(keta)
    #print(first, second)
    if keta>=k:
        answer+=cmb(keta, k)*(9**k)
    answer+=max(first-1, 0)*cmb(keta, k-1)*(9**(k-1))
    if k==1:
        answer+=1
    elif k==2:
        if keta>=k and second!=0:
            answer+=cmb(keta-1, k-1)*(9**(k-1))
        answer+=cmb(keta-1, k-2)*max(second-1, 0)*(9**(k-2))
        if keta>=k:
            answer+=cmb(keta-2, k-2)*(9**(k-2))
        else:
            if second!=0:
                answer+=1
    else:
        if keta>=k and second!=0:
            answer+=cmb(keta-1, k-1)*(9**(k-1))
        answer+=cmb(keta-1, k-2)*max(second-1, 0)*(9**(k-2))
        if keta>=k and third!=0:
            answer+=cmb(keta-2, k-2)*(9**(k-2))
        if keta>=k:
            answer+=third
        else:
            if third!=0:
                answer+=1
    
    print(answer)