n=int(input())
k=int(input())
w=[int(i) for i in str(n)]
x=len(w)
ans=chk=0
if n<10000:
    for i in range(1,n+1):
        chk=0
        p=i
        while p>0:
            if p%10>0:
                chk+=1
            p//=10
        ans += chk==k
    print(ans)
    exit()
if k==3:
    for a in range(x-2):
        e=1
        for b in range(a+1,x-1):
            f=1
            for c in range(b+1,x):
                if a==0 and e and f:
                    ans+=(w[a]-1)*w[b]*9
                    ans+=1*(w[b]-1)*9
                    ans+=1*1*w[c]
                    if w[b]!=0 and w[c]!=0:
                        e=f=0
                    elif w[c]!=0:
                        f=0
                elif a==0 and e:
                    ans+=(w[a]-1)*w[b]*9
                    ans+=1*(w[b]-1)*9
                    ans+=1*1*w[c]
                    if w[b]!=0:
                        e=0
                else:
                    ans+=9**3
elif k==2:
    for a in range(x-1):
        for b in range(a+1,x):
            if a==0 and b==1:
                ans+=(w[a]-1)*9
                ans+=1*w[b]
            elif a==0:
                ans+=w[a]*9
            else:
                ans+=9**2
else:
    ans=w[0]*(9**(x-1))
print(ans)
