The 2016 International Olympiad in Informatics is held in Russia.
The Russian flag has three horizontal bands. The top band is white, the middle band is blue, and the bottom band is red.
A teacher brought an N×M grid. Every cell of the grid is painted white, blue, or red. The assignment is to turn the grid into a Russian flag.
The rules are:
- You can pick any cell and repaint it in any color.
- Once the repainting is done, the upper part must be all white, the middle part all blue, and the lower part all red. Each of the three parts takes at least one row.
- The number of repainted cells must be as small as possible.
Write a program that computes the minimum number of cells you have to repaint to make the Russian flag under these rules.