Russian Flag

Choose the two row boundaries for the white, blue, and red bands so the number of repainted cells is smallest.

Easy3Brute forcePrefix sumInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

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×MN \times 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:

  1. You can pick any cell and repaint it in any color.
  2. 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.
  3. 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.

Input

The first line contains NN and MM separated by a space. (3N503 \le N \le 50, 3M503 \le M \le 50)

Each of the next NN lines contains one string of length MM.

Each string consists only of the uppercase letters "W", "B", and "R". "W" is white, "B" is blue, and "R" is red.

Output

Print the minimum number of cells that must be repainted to make the Russian flag.