N=int(input())
K=int(input())

List = list(str(N))

L = len(List)
a = int(List[0])

ans = 0
stop = 0

def cul2(L,a,stop,List):
  if L < 2:
    ans = 0
  elif L == 2:
    b = int(List[1])
    ans = int((a-1)*9+b)
  else:
    b = int(List[1])
    c = int(List[2])
    L = L - 1
    if b == 0:
      b = c
    ans = (a-1) * (9+9*(L-1)) + (b+(9*(L-1)))
    while stop == 0:
      L = L -1
      ans = int( ans + 9*(9+9*(L-1)) )
      if L == 0:
        stop = 1
  return ans 

if K == 1:
  ans = int(a + 9 * (L-1))
elif K == 2:
  if L < 2:
    ans = 0
  elif L == 2:
    ans = int((a-1)*9+b)
  else:
    b = int(List[1])
    c = int(List[2])
    L = L - 1
    if b == 0:
      b = c
    ans = (a-1) * (9+9*(L-1)) + (b+(9*(L-1)))
    while stop == 0:
      L = L -1
      ans = int( ans + 9*(9+9*(L-1)) )
      if L == 0:
        stop = 1
        
else:
  if L < 3:
    ans = 0
  else:
    b = int(List[1])
    c = int(List[2])
    d = int(List[3])
    L = L - 1
    
    e = int ( b * (10**(L-1)) + c * (10**(L-2)) + d * (10**(L-3)) )
    ee = list(str(e))
      
    ans = int ( (a-1) * cul2(L,a,stop,List) + cul2(len(ee),int(ee[0]),stop,ee) )
    while stop == 0:
      L = L -1
      List.pop(0)
      ans = int( ans + cul2(L,9,stop,List) )
      if L == 0:
        stop = 1   
    
print(ans)