#include <bits/stdc++.h>

using namespace std;

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

int main() {

  int H, W; cin >> H >> W;
  vector<string> G(H);
  rep(i, H) cin >> G[i];

  int ans = 1e9;
  
  REP(a, 1, H) REP(b, a+1, H) {
    int K = 0;
    rep(i, H) rep(j, W) {
      if(i < a) K += G[i][j] != 'W';
      if(a <= i && i < b) K += G[i][j] != 'B';
      if(b <= i) K += G[i][j] != 'R';
    }
    ans = min(ans, K);
  }

  cout << ans << endl;
  
  return 0;
}