#P452. 练82.1 涂国旗

练82.1 涂国旗

Description

According to a country's law, a flag consisting of N×MN×M 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 NN rows and MM 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 NN and MM. For 100% of the data, NN, M50M ≤ 50.
The next NN lines form a matrix, where each square is one of WW (white), BB (blue), or RR (red).

Output Format

A single integer representing the minimum number of squares that need to be painted.

Sample

4 5
WRWRW
BWRWB
WRWRW
RWBWR
11