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

from scipy.misc import comb
from math import factorial

n_d = len(str(n))
digits = str(n)

def get_num(top, k_val, d_num):
  #print(top, k_val, d_num)
  if d_num>n_d:
    return 1
  elif k_val==0:
    return 1
  elif top:
    below1 = get_num(True, k_val-1, d_num+1)
    below2 = (int(digits[d_num])-1) * get_num(False, k_val-1, d_num+1)
    below3 = get_num(False, k_val, d_num+1)
    return below1 + below2 + below3
  else:
    return factorial(n_d-d_num) / factorial(k_val) / factorial(n_d - d_num - k_val) * 9**(k_val)
    #return comb(n_d-d_num, k_val) * 9**(k_val)



if k<n_d :
  #a = comb(n_d-1, k)
  a = factorial(n_d-1) / factorial(k) / factorial(n_d-1 - k)
else:
  a = 0
a *= 9**k
#b = (int(digits[0]) - 1) * comb(n_d-1, k-1) * 9**(k-1)
c1 = get_num(True, k-1, 1)
c2 = (int(digits[0]) - 1) * get_num(False, k-1, 1)

#print(a, c1, c2)
print(int(a+c1+c2))