#include <cstdio>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n, m;
char x[50][51];
int w[51];
int b[51];
int r[51];

int main(){
	scanf("%d%d", &n, &m);
	rep(i, n){
		scanf("%s", x[i]);
	}

	rep(i, n){
		int c[3] = {0, 0, 0};
		rep(j, m){
			char p = x[i][j];
			++c[p == 'R' ? 2 : p == 'B'];
		}
		w[i + 1] = c[0] + w[i];
		b[i + 1] = c[1] + b[i];
		r[i + 1] = c[2] + r[i];
	}

	int ans = n * m;
	for(int i = 1; i <= n - 2; ++i){
		for(int j = 1; i + j <= n - 1; ++j){
			int k = n - i - j;
			int f = i * m - w[i];
			int g = j * m - (b[i + j] - b[i]);
			int h = k * m - (r[i + j + k] - r[i + j]);
			ans = min(f + g + h, ans);
		}
	}
	printf("%d\n", ans);
	return 0;
}