
#include <bits/stdc++.h>
using namespace std;

#define INF 999999999
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define all(v) v.begin(), v.end()
#define pub push_back
#define pob pop_back
#ifdef LOCAL
  #define de(e) cout << "L" << __LINE__ << ": " << e << "\n" // debug echo
  #define dr(e) cout << "L" << __LINE__ << ": " << #e << " -> " << e << "\n" // debug repr
#else
  #define de(e)
  #define dr(e)
#endif
#define out(fmt, ...) printf(fmt, __VA_ARGS__); printf("\n")
int gcd(int m, int n) { if((0 == m) || (0 == n)){return 0;} while(m != n){ if(m > n){m -= n;}else{n -= m;} } return m; }
int lcm(int m, int n) { if((0 == m) || (0 == n)){return 0;} return (m / gcd(m, n)) * n; }

//
// Implementation
//

int main() {
  int N;
  int M;
  scanf("%d %d", &N, &M);
  vector<string> flag(N);
  rep(i, N) cin >> flag[i];

  int ans = INF;

  for (int i=1; i<=N-2; i++) {

    for (int j=i+1; j<=N-1; j++) {
      dr(i << ":" << j);

      int acc = 0;
      
      for (int y=0; y<i; y++) {
        rep(x, M) {
          if (flag[y][x] != 'W') {
            acc++;
          }
        }
      }
  
      for (int y=i; y<j; y++) {
        rep(x, M) {
          if (flag[y][x] != 'B') {
            acc++;
          }
        }
      }

      for (int y=j; y<N; y++) {
        rep(x, M) {
          if (flag[y][x] != 'R') {
            acc++;
          }
        }
      }

      ans = min(ans, acc);
    }
  }

  out("%d", ans);
}