n=input();l=len(n)
k=int(input());x=0;c=-1;y=-1
for i in range(1,l):
  if int(n[i]):
    c=i
    continue
  if c!=-1 and int(n[i]):
    y=i
    break
if k==1:
  x=(l-1)*9 + int(n[0])
elif k==2 and l>1:
  x=81*(l-1)*(l-2)//2+9*(int(n[0])-1)*(l-1)+(int(n[c])+(l-c-1)*9 if c!=-1 else 0)
elif l>2:
  x=729*(l-3)*(l-2)//2+9*(int(n[0])-1)*(l-1)+(int(n[c])+(l-c-1)*9 if c!=-1 else 0)
print(x)