Given $L$ and $D$ find $X, \text { such that } X * 10^L + D \equiv 0 \mod M$
Since $10$ is relatively prime to $M$, it has an inverse modulo $M$, which can be found efficiently using the extended GCD algorithm. So you can simply calculate $X = -10^{-L}D$ (all computations modulo $M$).