program digit_sum
  implicit none
  integer(8), parameter :: md = 1000000007_8
  character(10000) :: k
  integer :: d, n, i, j, l, x = 0, y = 1, t, m = 0
  integer(8) :: dp(0:1,0:100,0:1) = 0_8
  read(*,*) k
  read(*,*) d
  n = len_trim(k)
  dp(0,0,1) = 1_8
  do i = 1, n
    t = ichar(k(i:i))-48
    dp(y,:,:) = 0_8
    dp(y,mod(m+t,d),1) = dp(x,m,1)
    do j = 0, d-1
      do l = 0, t-1
        dp(y,mod(j+l,d),0) = mod(dp(y,mod(j+l,d),0)+dp(x,j,0)+dp(x,j,1),md)
      end do
      do l = t, 9
        dp(y,mod(j+l,d),0) = mod(dp(y,mod(j+l,d),0)+dp(x,j,0),md)
      end do
    end do
    m = mod(m+t,d)
    x = xor(x,1)
    y = xor(y,1)
  end do
  write(*,'(i0)') modulo(dp(x,0,0)+dp(x,0,1)-1_8,md)
end program digit_sum