N = int(input())
K = int(input())
ans = 0
while N!=0:
    n = str(N)
    if len(n)<K:break

    if n[1:].count("9")==len(n)-1:
        if K==1:ans+=int(n[0])
        elif K==2:
            for i in range(1,len(n)):
                ans+=int(n[0])*9
        else:
            for i in range(1,len(n)-1):
                for j in range(i+1,len(n)):
                    ans+=int(n[0])*9*9
    else:
        if K==1:ans+=1
        elif K==2:
            k = 0
            for i in range(1,len(n)):
                if k==0:
                    ans += int(n[i])
                    if n[i]!="0":k=1
                else:
                    ans+=9
        else:
            k = 0
            for i in range(1,len(n)-1):
                for j in range(2,len(n)):
                    if k==0:
                        ans += int(n[i])*9
                    else:
                        ans += 9*9
                if n[i]!="0":k=1
    if len(n)==1:N = 0
    elif n[1:].count("9")==len(n)-1:N = 10**(len(n)-1)-1
    else:N = int(n[0])*(10**(len(n)-1))-1
print(ans)