Hands down the M4. I have both and almost everyone who has shot both prefer the M4. It’s much smoother and has a better recoil mitigation system.
Once you put about 500 rounds through the M4, it’ll eat anything, including birdshot. You can then practice for cheap.
My M2 has a fixed stock, while my M4 is set up with a telescoping stock. The telescoping stock is great if you’re in a tight environment. One other advantage of the telescoping stock is that it’s adjustable, so shooters with shorter arms will like it. I’m not sure the M2 has a telescoping stock option.
Finally, the M4 is real world tested by the military.
It’s not a close decision.