#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int N, M; cin >> N >> M;
	int A[3][55] = {};
	fill(A[0], A[3], M);
	rep(i, 0, N)rep(j, 0, M) {
		char c; cin >> c;
		if (c == 'W')A[0][i]--;
		if (c == 'B')A[1][i]--;
		if (c == 'R')A[2][i]--;
	}
	rep(i, 0, N)rep(h, 0, 3)A[h][i + 1] += A[h][i];
	int ans = INF;
	rep(a, 0, N - 2)rep(b, a + 1, N - 1) {
		int temp = 0;
		temp += A[0][a];
		temp += A[1][b] - A[1][a];
		temp += A[2][N - 1] - A[2][b];
		ans = min(ans, temp);
	}
	cout << ans << endl;
	return 0;
}