n = int(input())
k = int(input())

s = str(n)
a = len(str(n))
b = n//10**(a-1)
c = int(s[1])
d = int(s[2])
e = int(s[3])
def F1(i):
  A = len(str(i))
  B = i//10**(A-1)
  return(9*(A-1)+B)
def F2(i):
  A = len(str(i))
  B = i//10**(A-1)
  S = str(i)
  C = int(S[1])
  return((A-1)*(A-2)*81/2 + (B-1)*(A-1)*9+(A-2)*9*C +1)

if k ==1:
  print(9*(a-1)+b)

if k == 2:
   ans = (a-1)*(a-2)*81/2 + (b-1)*(a-1)*9+(a-2)*9*c +1
   print(ans)
if k ==3:
   ans = (a-1)*(a-2)*(a-3)//2*243 + F2(10**(a))*(b-1)+ F1(10**(a-1))*(c-1)+(a-3)*9*d +1
   print(ans)