import math
from scipy.misc import comb

N = input()
l = len(N)

number = int(input())
mam = comb(l, number, exact=True)*9**number
if number == 1:
  mam1 = comb(l-1, number, exact=True)*9**number
  mam1 += int(N[0])
  print(mam1)
if number == 2:
  mam1 = comb(l-1, number, exact=True)*9**number
  mam1 += (int(N[0])-1)*comb(l-1, number-1, exact=True)*9**(number-1)
  mam1 += int(N[1])+ (l-2)*9   
  print(mam1)
if number == 3:
  mam1 = comb(l-1, number, exact=True)*9**number
  mam1 += (int(N[0])-1)*comb(l-1, number-1, exact=True)*(9**(number-1))
  mam1 += (int(N[1])-1)*comb(l-2, number-2, exact=True)*9**(number-2) + comb(l-2, number-1, exact=True)*9**(number-1)
  mam1 += int(N[2])+ (l-3)*9
  print(mam1)