#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int n,m;
	cin>>n>>m;
	vvi in(n,vi(3));
	rep(i,n)rep(j,m){
		char c;
		cin>>c;
		if(c=='W')in[i][0]++;
		else if(c=='B')in[i][1]++;
		else in[i][2]++;
	}
	vvi dp(3,vi(n+1,inf));
	dp[0][0]=0;
	rep(i,n)dp[0][i+1]=dp[0][i]+m-in[i][0];
	loop(i,1,n)dp[1][i+1]=min(dp[0][i],dp[1][i])+m-in[i][1];
	loop(i,2,n)dp[2][i+1]=min(dp[1][i],dp[2][i])+m-in[i][2];
	cout<<dp[2][n]<<endl;
}