An n*m grid of bulbs was given. Some were on (denoted by ‘O’) and some were off (denoted by ‘X’). When you toggle the state of a bulb, the state of the bulbs adjacent to it gets toggled too. Return the minimum number of toggles needed to switch all the bulbs off or -1 if it is not possible.