#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	vector<string>s;
	for (int i = 0; i < n; i++){
		string st; cin >> st;
		s.push_back(st);
	}
	int num = n*m;
	for (int i = 1; i < n - 1; i++){
		for (int j = i + 1; j < n; j++) {
			int k;
			int p = 0;
			for (k = 0; k < i; k++){
				for (int i = 0; i < m; i++){
					if (s[k][i] != 'W'){
						p++;
					}
				}
			}
			for (k = i; k < j; k++) {
				for (int i = 0; i < m; i++) {
					if (s[k][i] != 'B') {
						p++;
					}
				}
			}
			for (k = j; k  < n; k++){
				for (int i = 0; i < m; i++) {
					if (s[k][i] != 'R') {
						p++;
					}
				}
			}
			num = min(num, p);
		}
	}
	cout << num << endl;
	return 0;
}