n = gets.chomp
m = gets.to_i
size = n.size
dp = Array.new(size + 1) { Array.new(2) { Array.new(size + 1) { 0 } } }
dp[0][0][0] = 1

0.upto(size - 1) do |i|
  2.times do |j|
    size.times do |k|
      d = n[i].to_i
      0.upto(j == 0 ? d : 9) do |l|
        dp[i + 1][j == 1 || l < d ? 1 : 0][l != 0 ? k + 1 : k] += dp[i][j][k]
      end
    end
  end
end

puts dp[size][0][m] + dp[size][1][m]
