You can always do it if $N \ge M$. Reduce all the numbers $\pmod M$. If any are zero, put multiply signs everywhere. If not, imagine putting plus signs everywhere and keeping track of the running sum. Since there are at least $M$, either one is $0 \pmod M$ or two are the same $\pmod M$. If one of the running sums is zero, put parentheses around that addition and multiply all the rest of the numbers. If two of the running sums are the same, start after the first one and go to the end of the second. The sum of that interval will be $0 \pmod M$. Multiply by all the other numbers.
If $M$ is composite and $N$ is at least the sum of the prime factors of $M$ (counting multiplicity) you can succeed. For example, let $M=12, N=7$. We have shown that the first three elements can contribute a factor $3$ and each of the pairs of the last four can contribute a factor $2$ so we can succeed.
If $N$ is at least the sum of the prime factors of $M$ you can succeed. It may be possible to succeed with fewer-I thought I had a proof that you couldn't but it fails.