local mfl = math.floor
local ns = io.read()
local k = io.read("*n")
if k == 1 then
  local a = tonumber(ns:sub(1, 1))
  print(a + 9 * (#ns - 1))
elseif k == 2 then
  if #ns == 1 or ns == "10" then print(0)
  else
    local a = tonumber(ns:sub(1, 1))
    local b = tonumber(ns:sub(2, 2))
    -- use 1st but not max
    local ret = (#ns - 1) * 9 * (a - 1)
    -- don't use 1st
    ret = ret + 81 * mfl((#ns - 1) * (#ns - 2) / 2)
    -- use 1st by max
    ret = ret + b + 9 * (#ns - 2)
    print(ret)
  end
else
  if #ns < 3 or ns == "100" then print(0)
  else
    local a = tonumber(ns:sub(1, 1))
    local b = tonumber(ns:sub(2, 2))
    local c = tonumber(ns:sub(3, 3))
    -- don't use 1st
    ret = 729 * mfl((#ns - 1) * (#ns - 2) * (#ns - 3) / 6)
    -- use 1st but not max
    ret = ret + (a - 1) * 81 * mfl((#ns - 1) * (#ns - 2) / 2)
    -- use 1st by max
    do
      -- don't use second
      ret = ret + 81 * mfl((#ns - 2) * (#ns - 3) / 2)
      -- use 2nd but not max
      ret = ret + (b - 1) * 9 * (#ns - 2)
      -- use 2nd by max
      ret = ret + c + 9 * (#ns - 3)
    end
    print(ret)
  end
end
