tmp=input()
n=int(tmp)
l=len(tmp)

k=int(input())
if k==1:
    ans=9*(l-1)
    last=int(tmp[0])
    ans+=last
    print(ans)
    exit()
if k==2:
    c=l-2
    ans=(9**2)*((c*(c+1))//2)
    num=0
    for i in range(1,l):
        for head_i in range(9,0,-1):
            for tail_i in range(9,0,-1):
                cal=str(head_i)
                cal+="0"*len(tmp[1:i])
                cal+=str(tail_i)
                cal+="0"*len(tmp[i+1:])
                if int(cal)<=n:
                    num+=1
    ans+=num
    print(ans)
    exit()
print(ans)