One day Harry Potter came to a magic room, in which there are some shadow monsters sent by the black wizard waiting for him. Fortunately, shadow monsters can only live in areas where there are no lights shining, there are n*m lamps on the roof of the room, every little lamp can only illuminate the scope of the fixed area, and all the area of lights shining don't overlap, some lamps on, some lamps off, the areas below the closed lamps will appear the shadow, and in these areas shadow monsters will attack Harry Potter. Now Harry Potter comes to you and gives you the previous state of the room lights, Harry Potter can control the light switch in a remote place .The state of a light will change as follows: if a lamp state changed, the state of the lights which before it, after it, left to it or right to it will all change. Your task is to calculate how many times we need at least to turn on all the lights by changing the state of the lamps.