def comb(n,r)
  r.times.inject(1){|s,i| s * (n - i) / (i + 1) }
end
N = gets.chomp.chars.map(&:to_i)
K = gets.to_i
ans = 0

N.each.with_index(1).inject(0) do |nz,(d, i)|
  break if nz == K
  t = N.size - i
  if !d.zero?
    ans += (d - 1) * comb(t, K - nz - 1) * (9 ** (K - nz - 1))
    ans += comb(t, K - nz) * (9 ** (K - nz))
    nz + 1
  else
    nz
  end
end
puts ans + 1
