#include <iostream>
using namespace std;
int main(void){

	int n, m;

	cin >> n >> m;

	char date[64][64];

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> date[i][j];
		}
	}
	int count, ans = 999999;

	for (int WB = 1; WB < n - 1; WB++) {
		for (int BR = 1; WB + BR < n; BR++) {
			
			count = 0;
			int row = 0;
			for (int i = 0; i < WB; i++) {
				for (int i2 = 0; i2 < m; i2++) {
					if (date[row][i2] != 'W') { count++; }
				}
				row++;
			}

			for (int i = 0; i < BR; i++) {
				for (int i2 = 0; i2 < m; i2++) {
					if (date[row][i2] != 'B') { count++; }
				}
				row++;
			}

			for (int i = 0; i + WB + BR < n; i++) {
				for (int i2 = 0; i2 < m; i2++) {
					if (date[row][i2] != 'R') { count++; }
				}
				row++;
			}
			if (ans > count) { ans = count; }
		}
	}
	cout << ans << endl;
}