#include <bits/stdc++.h>
using namespace std;

int white[64];
int blue[64];
int red[64];

int main()
{
    int h, w;

    cin >> h >> w;
    vector<string> flag(h);
    for (int i = 0; i < h; i++){
        cin >> flag[i];
        white[i] = w - count(flag[i].begin(), flag[i].end(), 'W');
        blue[i] = w - count(flag[i].begin(), flag[i].end(), 'B');
        red[i] = w - count(flag[i].begin(), flag[i].end(), 'R');
    }

    int mini = h * w;
    int W = 0;
    for (int i = 0; i < h - 2; i++){
        W += white[i];
        int B = 0;
        int R = accumulate(red + i + 1, red + h, 0);
        for (int j = i + 1; j < h - 1; j++){
            B += blue[j];
            R -= red[j];
            mini = min(mini, W + B + R);
            // cout << " " << W << " " << B << " " << R << endl;
        }
    }

    cout << mini << endl;

    return 0;
}