local mod = 1000000007
local function badd(x, y) return (x + y) % mod end

local s = io.read()
local d = io.read("*n")
local dpmax, dpnormal = {}, {}
for i = 1, d do
  dpmax[i] = 0
  dpnormal[i] = 0
end
dpmax[d] = 1
local nxt_max, nxt_normal = {}, {}
for i = 1, #s do
  for j = 1, d do
    nxt_max[j] = 0
    nxt_normal[j] = 0
  end
  local v = s:sub(i, i):byte() - 48
  for src = 1, d do
    for add = 0, v do
      local dst = (add + src) % d
      if dst == 0 then dst = d end
      if add == v then
        nxt_max[dst] = badd(nxt_max[dst], dpmax[src])
      else
        nxt_normal[dst] = badd(nxt_normal[dst], dpmax[src])
      end
    end
    for add = 0, 9 do
      local dst = (add + src) % d
      if dst == 0 then dst = d end
      nxt_normal[dst] = badd(nxt_normal[dst], dpnormal[src])
    end
  end
  for j = 1, d do
    dpmax[j] = nxt_max[j]
    dpnormal[j] = nxt_normal[j]
  end
end
local ret = badd(dpmax[d], dpnormal[d])
ret = badd(ret, mod - 1)
print(ret)
