#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define INF (1<<29)

int main() {
	int n, m;
	cin >> n >> m;
	string maps[50];
	REP(i, n) cin >> maps[i];
	
	int ans = INF;
	FOR(w, 1, n + 1) FOR(b, 1, n - w + 1) FOR(r, 1, n - w - b + 1) {
		int cnt = 0;
		FOR(i, 0, w) cnt += m - count(maps[i].c_str(), maps[i].c_str() + maps[i].size(), 'W');
		FOR(i, w, w + b) cnt += m - count(maps[i].c_str(), maps[i].c_str() + maps[i].size(), 'B');
		FOR(i, w + b, n) cnt += m - count(maps[i].c_str(), maps[i].c_str() + maps[i].size(), 'R');
		
		ans = min(ans, cnt);
	}
	
	cout << ans << endl;
	
	return 0;
}