#include<cstdio>
#include<iostream>
using namespace std;
int co[50][3]={0};
int func(int N,int M);
int main ()
{
    int n,m,ans;
    char k[51][51];
    scanf("%d%d",&n,&m);
    for(int i=n;i<50;i++){
        co[i][0]=-1;
        co[i][1]=-1;
        co[i][2]=-1;
    }
    for(int i=0;i<n;i++){
        scanf("%s",&k[i]);
        for(int j=0;j<m;j++){
            if(k[i][j]=='W') co[i][1]++,co[i][2]++;
            if(k[i][j]=='B') co[i][0]++,co[i][2]++;
            if(k[i][j]=='R') co[i][0]++,co[i][1]++;
        }
    }
    ans=func(0,0);
    printf("%d\n",ans);
    return 0;
}
int func(int N,int M)
{
    int B,C;
    if(M>2) return 1000;
    if(co[N+1][M]==-1&&M!=2) return 1000;
    if(co[N+1][M]==-1&&M==2) return co[N][M];
    B=func(N+1,M+1);
    C=func(N+1,M);
    if(B>C) return co[N][M]+C;
    else if(B<=C) return co[N][M]+B;
}