s = gets.rstrip.chars.map(&:to_i)
k = gets.to_i
n = s.size

dp = Array.new(n + 1) { Array.new(2) { Array.new(4, 0)}}

dp[1][0][0] = 0
dp[1][0][1] = s[0] - 1
dp[1][1][0] = 1
dp[1][1][1] = 1

1.upto(n-1) do |i|
  2.times do |smaller|
    4.times do |count|
      (smaller != 0 ? 10 : s[i] + 1).times do |x|
        snext = (smaller == 1 || x < s[i] ? 1 : 0)
        cnext = x > 0 ? count + 1 : count
        if cnext < 4
          dp[i + 1][snext][cnext] += dp[i][smaller][count]
        end
      end
    end
  end
end

p dp[n][0][k] + dp[n][1][k]
