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

int main() {
	int N, M, ans = INT_MAX;
	cin >> N >> M;
	vector<string> a(N);
	for (string& i : a) cin >> i;
	for (int i = 1; i < N - 1; ++i) {
		for (int j = 1 + i; j < N; ++j) {
			int b = 0;
			for (int k = 0; k < i; ++k) {
				for (char& l : a[k]) {
					if ('W' != l) ++b;
				}
			}
			for (int k = i; k < j; ++k) {
				for (char& l : a[k]) {
					if ('B' != l) ++b;
				}
			}
			for (int k = j; k < N; ++k) {
				for (char& l : a[k]) {
					if ('R' != l) ++b;
				}
			}
			ans = min(ans, b);
		}
	}
	cout << ans << endl;
}
