#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(){
	int n, m, nonw[60] = {}, nonb[60] = {}, nonr[60] = {};
	int ans = 2000000000;
	string flag[60];
	cin >> n >> m;
	for(int i = 0;i<n;i++){
		cin >> flag[i];
		for(int j = 0;j<m;j++){
			if (flag[i][j] != 'W') nonw[i]++;
			if (flag[i][j] != 'B') nonb[i]++;
			if (flag[i][j] != 'R') nonr[i]++;
		}
		nonw[i + 1] += nonw[i];
		nonb[i + 1] += nonb[i];
		nonr[i + 1] += nonr[i];
	}
	for(int i = 0;i<n-2;i++){
		for(int j = i+1;j<n-1;j++){
			int tmp = nonw[i] + nonb[j] - nonb[i] + nonr[n] - nonr[j];
			ans = min(ans, tmp);
		}
	}
	cout << ans << endl;
return 0;
}