FIR filter design by the Fourier transform method
Some papers provide rule-of-thumb formula for the filter length (and coefficient quantization), for instance:


Accurate estimation of minimum filter length for optimum FIR digital filters, 2000, Ichige et al.
On computational complexity in digital filters, 1981, Bellanger
FIR Digital Filter Design Techniques Using Weighted Chebyshev Approximation, 1975, Rabiner et al.


The one I generally  use in lectures is borrowed from the second paper, for a low-pass filter with the following design:



Then, the estimated filter length $N$ (apparently $2M+1$ for you) is, with sampling frequency $f_s$:

$$ N = \frac{2 f_s}{3(f_2-f_1)}\log_{10} \left(\frac{1}{10\delta_1\delta_2}\right)$$