import math
import itertools as it
import fractions as fra
N=int(input())
K=int(input())
answer=0

if K==1:
    if N>=10:
        print((int(math.log10(N))-1)*9+int(str(N)[0])+9)
    else:
        print(N)
elif K==2:
    if N>=100:
        for i in range(1,int(math.log10(N))):
            answer+=81*i
        answer+=(N//(10**int(math.log10(N))))*9*int(math.log10(N))
        print(answer)
    else:
        for i in range(1,N+1):
            if i>10:
                if i%10!=0:
                    answer+=1
        print(answer)
else:
    if N>=1000:
        for i in range(2,int(math.log10(N))):
            answer+=729*math.factorial(i)/(math.factorial(i-2)*math.factorial(2))
        answer+=N//(10**int(math.log10(N)))*81*math.factorial(int(math.log10(N))-1)/(math.factorial(int(math.log10(N))-3)*2)
        print(answer)
    else:
        for i in range(1,N+1):
            base=str(i)
            if len(base)-base.count("0")==3:
                answer+=1
        print(answer)