solving mg problem