Assuming the total length and width of the box is 8 x 8 x 8in which tends to be a fairly common measurement among Halloween box retailers, and the M&M's being used in the picture, are "normal-size" in diameter, approximately 1.04 centimeters, we can give an approximate guess although the anatomy and structure of the M&M's are quite round, so they often don't stack which can create a large variability among totals.
After some test/trial errors, and consulting with some experienced M&M guesser, stackers, it appears on a general basis 637 M&M's will fit in two and a half cups. I was able to construct an 8x8x8 box and found that usually, five cups would fit the line similar to the one shown in the first photo. So that would equate up to around, 1274 M&M's.
So, 1274 M&M's is my answer.