#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
  int n, m;
  char s[50][51];
  int counter[50][3];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  for (int i = 0; i < n; i++) {
    counter[i][0] = counter[i][1] = counter[i][2] = 0;
    for (int j = 0; j < m; j++) {
      if (s[i][j] == 'W') counter[i][0]++;
      if (s[i][j] == 'B') counter[i][1]++;
      if (s[i][j] == 'R') counter[i][2]++;
    }
  }
  int ans = 1000000;
  for (int i = 1; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      int sum = 0;
      for (int r = 0; r < n; r++) {
        if (r < i) sum += counter[r][0];
        else if (r < j) sum += counter[r][1];
        else sum += counter[r][2];
      }
      ans = min(ans, n * m - sum);
    }
  }
  printf("%d\n", ans);
}

