How can I design a beam former (with weigth vector $w$) that protects a signal coming from an angle of arrival $\theta_0$ and completely suppresses signals coming from $\theta_1,\theta_2,...,\theta_k$? How should I choose the number of elements $M$?
For spatial filtering there are numerous beamforming techniques and it will be difficult to compare all here, there are numerous resource available on internet.
Just to give you insight I am giving brief description of well known beamforming techniques
Phased shift beamformer also known as conventional beamformer: This beamforming techniques tries to add constructively the signal from the provide direction. This algorithm thus shifts the signal such that they align perfectly at the provided direction and thus sums up constructively. This algorithm has the worst angular resolution amongst different beam forming techniques as all signals from other directions are also included into the result. The resolution is in the range of the beam width of linear array.
Minimum variance distortionless response (MVDR) beamformer also known as CAPON beamformer: This beamformer is based on matching the array response matrix with the inverse of the sample correlation matrix, thus enhancing the signal from considered direction and also suppressing the effects from the interfere signals from different direction other than the direction under consideration. The resolution of MVDR is far better than phased shift beamformer.
Among these two algorithm stated above the MVDR has benefit related to separation between two signals but on the expense of more computations. It would be of worth to also look into the Linear constraint minimum variance beamformer (LCMV).
completely suppresses signals
As far i know, there is no such algorithm which can complete suppress the signal from other directions as it depends on many factors. But all beam forming algorithms can maximize the signal from provided direction and minimize the signal from the other direction. If you want the best result I would suggest also to look into eigen space based beamformer techniques.
How should I choose the number of elements M
The number of elements 'M' provides you degree of freedom so more 'M' would be beneficial but it limits the size of antenna. Mostly you have to decide the resolution you need for the beam former and then choose 'M' accordingly it is different for each algorithm. Higher 'M' is beneficial but you have to draw a line somewhere.