N=int(input())
strN = str(N)
K=int(input())
d = len(strN)

# define functions to simplify
def N_(i):
  return int(strN[i])

# n choose 2 or 3
def C2(n):
  return n*(n-1)//2

def C3(n):
  return n*(n-1)*(n-2)//6

# 0ではない桁が先頭に並ぶ場合、並ばない場合等に場合分け。
if K==1:
  print(int(strN[0]) + 9*(d-1))
elif K == 2:
  sum1 = N_(1) + (N_(0)-1)*9 + N_(0)*9*(d-2)
  sum2 = 9*9*C2(d-1)
  print(sum1+sum2)
else:
  sum1 = (N_(0)-1)*9*9*(d-2) + (N_(1)-1)*9*(d-2) + N_(2) + 9*(d-3)
  sum2 = N_(0)*9*9*C2(d-2)
  sum3 = 9*9*9*C3(d-1)
  print(sum1+sum2+sum3)