# include <iostream>
# include <algorithm>

int h, W;

int w[50], b[50], r[50];

int main() {
	std::cin >> h >> W;
	char ch;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < W; ++j) {
			std::cin >> ch;
			if (ch == 'W') {
				++w[i];
			}
			else if (ch == 'B') {
				++b[i];
			}
			else {
				++r[i];
			}
		}
	}
	for (int i = 1; i < h; ++i) {
		w[i] += w[i - 1];
		b[i] += b[i - 1];
		r[i] += r[i - 1];
	}

	int min = 2600;

	for (int i = 0; i < h - 2; ++i) {
		for (int j = i + 1; j < h - 1; ++j) {
			int sum = 0;
			sum += W*(i + 1) - w[i];//2
			sum += W*(j - i) - (b[j] - b[i]);//3
			sum += W*(h - j - 1) - (r[h-1] - r[j]);//
			min = std::min(min, sum);
		}
	}
	std::cout << min << std::endl;
	return 0;
}