By the above logic, the other envelope contains $(M/2) with probability 0.5 and $(2*M) with probability 0.5, so if you switch you expect to gain $M/4.

One of the problems with this approach to game theory is that although "statistically" one can "expect" to gain $M/4, no such real alternative exists in the game. This is the same situation as town in which half the population makes $10,000/year, and half make $110,000/year. The mean income is $60,000/year, but NOBODY actually has that income! It's a situational failure of the descriptive statistics.

In fact, any situation where one can stand either to gain or lose by "choosing the other envelope" versus keeping the one you have can be *described* mathematically, but not "solved" that way in real life. It ultimately comes down to whether the individual is a risk-taker or prefers a sure thing.