N = gets.to_i
K = gets.to_i

def combi(n, k)
  return 0 if n < k
  k = n - k if 2 * k > n
  return 1 if k == 0
  ((n - k + 1)..n).reduce(&:*) / ((1..k).reduce(&:*))
end

l = Math.log10(N).floor + 1
sum = 0
n_1 = N / 10 ** (l - 1)
n_2 = (N / 10 ** (l - 2)) % 10 
sum += combi(l - 1, K) * 9 ** K
sum += [n_2, 0].max
sum += [(n_1 - 1) * 9, 0].max
sum += n_1 * 9 * (K == 1 ? 0 : combi(l - 2, K - 1))

puts sum
