// Problem: P3392 涂国旗
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P3392
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// User: Pannnn
#include <bits/stdc++.h>
using namespace std;
int cntDiff(vector<string> &info, int row1, int row2) {
int cnt = 0;
for (int i = 0; i <= row1; ++i) {
for (int j = 0; j < info[i].size(); ++j) {
if (info[i][j] != 'W') {
++cnt;
}
}
}
for (int i = row1 + 1; i <= row2; ++i) {
for (int j = 0; j < info[i].size(); ++j) {
if (info[i][j] != 'B') {
++cnt;
}
}
}
for (int i = row2 + 1; i < info.size(); ++i) {
for (int j = 0; j < info[i].size(); ++j) {
if (info[i][j] != 'R') {
++cnt;
}
}
}
return cnt;
}
int getMinCnt(vector<string> &info) {
int res = INT_MAX;
// 遍历所有格子划分情况,计算要修改多少次,注意,每一行至少为1
for (int i = 0; i < info.size(); ++i) {
for (int j = i + 1; j < info.size() - 1; ++j) {
res = min(res, cntDiff(info, i, j));
}
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<string> info(n);
for (int i = 0; i < n; ++i) {
cin >> info[i];
}
int res = getMinCnt(info);
cout << res << endl;
return 0;
}