Because of its age, the City Hall has suffered damage to one of its walls. A matrix with M rows and N columns represents the encoded image of that wall, where 1 represents an intact wall and 0 represents a damaged wall (like in Figure-1).
1110000111
1100001111
1000000011
1111101111
1110000111
Figure-1
To repair the wall, the workers will place some blocks vertically into the damaged area. They can use blocks with a fixed width of 1 and different heights of {1,2, ..., M}.
For a given image of the City Hallˇs wall, your task is to determine how many blocks of different heights are needed to fill in the damaged area of the wall, and to use the least amount of blocks.