Everything looks good until we realize that M appears on boths sides of the equation.

So we must use an iterative procedure to find the solution.

This type of iterative solution is acutually fairly common:

If we knew M the cost function would be quadratic. So we guess M and

then solve as if it were quadratic.