#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    string s[h];
    rep (i, h) cin >> s[i];

    int ans = 1e9;
    range (WB, 1, h - 1) range (BR, WB + 1, h) {
        int sum = 0;
        rep   (i, WB)     rep (j, w) sum += s[i][j] != 'W';
        range (i, WB, BR) rep (j, w) sum += s[i][j] != 'B';
        range (i, BR,  h) rep (j, w) sum += s[i][j] != 'R';
        ans = min(ans, sum);
    }
    cout << ans << endl;

    return 0;
}
