def top(x):
  return int(x[0])
def digit(x):
  return len(x)

def nonzero_one(x):
  return (digit(x)-1)*9+top(x)

def nonzero_two(x):
  rt=0
  xtop=top(x)
  dig=digit(x)
  rt+=81*(dig-1)*(dig-2)//2
  rt+=(xtop-1)*9*(dig-1) 
  rt+=int(x[1])+9*(dig-2)
  return rt

def nonzero_three(x):
  rt=0
  xtop=top(x)
  dig=digit(x)
  rt+=729*(dig-1)*(dig-2)*(dig-3)//6
  rt+=(xtop-1)*81*(dig-1)*(dig-2)//2
  rt+=nonzero_two(x[1:])
  return rt

N=input()
K=int(input())
if K==1:
  print(nonzero_one(N))
elif K==2:
  print(nonzero_two(N))
else:
  print(nonzero_three(N))
