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, bpos = 0, #ns + 1
    for i = 2, #ns do
      if ns:sub(i, i) ~= "0" then
        b, bpos = tonumber(ns:sub(i, i)), i
        break
      end
    end
    -- use 1st but not max
    local ret = (#ns - 1) * 9 * (a - 1)
    -- don't use 1st
    ret = ret + 81 * (#ns - 1) * (#ns - 2) // 2
    -- use 1st by max
    if bpos <= #ns then
      ret = ret + b + 9 * (#ns - bpos)
    end
    print(ret)
  end
else
  if #ns < 3 then print(0)
  else
    local a = tonumber(ns:sub(1, 1))
    local b, bpos = 0, #ns + 1
    for i = 2, #ns do
      if ns:sub(i, i) ~= "0" then
        b, bpos = tonumber(ns:sub(i, i)), i
        break
      end
    end
    local c, cpos = 0, #ns + 1
    for i = bpos + 1, #ns do
      if ns:sub(i, i) ~= "0" then
        c, cpos = tonumber(ns:sub(i, i)), i
        break
      end
    end
    -- don't use 1st
    ret = 729 * (#ns - 1) * (#ns - 2) * (#ns - 3) // 6
    -- use 1st but not max
    ret = ret + (a - 1) * 81 * (#ns - 1) * (#ns - 2) // 2
    -- use 1st by max
    if bpos <= #ns - 1 then
      -- don't use second
      ret = ret + 81 * (#ns - bpos) * (#ns - bpos - 1) // 2
      -- use 2nd but not max
      ret = ret + (b - 1) * 9 * (#ns - bpos)
      -- use 2nd by max
      if cpos <= #ns then
        ret = ret + c + 9 * (#ns - cpos)
      end
    end
    print(ret)
  end
end
