N = gets.strip
K = gets.to_i
L = N.length

c = ->(m, n){n.times.inject(1){|p, i| p * (m - i)/(i + 1)}}
f = ->(r, k){9**k * c[r, k]}
ans = L >= K ? 1 : 0
k = K
N.chars.map(&:to_i).each.with_index(1) do |d, i|
  break if k.zero?
  unless d.zero?
    ans += f[L - i, k] + (d - 1)*f[L - i, k - 1]
    k -= 1
  end
end
puts ans