#P452. 练82.1 涂国旗
练82.1 涂国旗
Description
According to a country's law, a flag consisting of small squares is legal if it follows these rules:
The top several rows (at least one row) must be entirely white;
The next several rows (at least one row) must be entirely blue;
The remaining rows (at least one row) must be entirely red.
There is a chessboard-like cloth divided into rows and columns, where each square is either white, blue, or red. Little A wants to turn this cloth into a legal flag by painting over some squares to cover their previous colors.
Little A is lazy and wants to paint the minimum number of squares to make this cloth a legal flag.
Input Format
The first line contains two integers and . For 100% of the data, , .
The next lines form a matrix, where each square is one of (white), (blue), or (red).
Output Format
A single integer representing the minimum number of squares that need to be painted.
Sample
4 5
WRWRW
BWRWB
WRWRW
RWBWR11