Solution (source code)

= Solution

Let $n_1,\ldots,n_r$ generate $N$, and let the images of $m_1,\ldots,m_s$ generate $M/N$. For any $m\in M$, subtracting a suitable linear combination of the $m_j$ leaves an element of $N$, which is a combination of the $n_i$. Thus
$$
\boxed{M=Rn_1+\cdots+Rn_r+Rm_1+\cdots+Rm_s.}
$$