#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<char>> F(N, vector<char>(M));
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j)
      cin >> F[i][j];

  int ans = 1000000001;
  for (int w = 0; w < N - 2; ++w) {
    for (int b = w + 1; b < N - 1; ++b) {
      int diff = 0;
      for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
          if (0 <= i && i <= w && F[i][j] != 'W')
            ++diff;
          if (w < i && i <= b && F[i][j] != 'B')
            ++diff;
          if (b < i && i < N && F[i][j] != 'R')
            ++diff;
        }
      }

      ans = min(diff, ans);
    }
  }

  cout << ans << endl;
}
