#include<bits/stdc++.h>

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

using namespace std;

int h,w,sum[3][50];
char c[51][51], color[] = {'W','B','R'};

void preprocess(int type) {
  rep(y,h) {
    sum[type][y] = ((y-1>=0)?sum[type][y-1]:0);
    rep(x,w) sum[type][y] += ( color[type] == c[y][x] );
  }
}

inline int calc(int type,int i,int j) { return sum[type][i] - sum[type][j]; }

void compute() {
  rep(i,3) preprocess(i);
  int mini = INT_MAX;
  rep(i,h-2) REP(j,i+1,h-1) mini = min(mini,(sum[1][i]+sum[2][i])+(calc(0,j,i)+calc(2,j,i))+(calc(0,h-1,j)+calc(1,h-1,j)));
  cout << mini << endl;
}

int main() {
  cin >> h >> w;
  rep(i,h) scanf(" %s",&c[i][0]);
  compute();
  return 0;
}