#include<cstring>
#include<iostream>
#include<cstdio>
using namespace std;
int B,n,m;
bool a[105][105],b[105][105];
bool dfs(int x,int y){
int i,j;
if (x==n+2-B){
for (i=x;i<=n;i++)
for (j=1;j<=m;j++)
if (a[i][j]!=b[i][j]) return 0;
return 1;
}
if (y==m+2-B){
for (i=y;i<=m;i++){
if (a[x][i]!=b[x][i]) return 0;
}
return dfs(x+1,1);
}
if (b[x][y]!=a[x][y]){
for (i=0;i<B;i++)
for (j=0;j<B;j++){
b[x+i][y+j]=a[x][y];
}
}
return dfs(x,y+1);
}
int main(){
freopen("skicourse.in","r",stdin);
freopen("skicourse.out","w",stdout);
int i,j;
char ch;
scanf("%d%d",&n,&m);
for (i=1;i<=n;i++){
getchar();
for (j=1;j<=m;j++){
ch=getchar();
if (ch=='R') a[i][j]=1;
else a[i][j]=0;
}
}
for (B=min(n,m);B;B--){
memset(b,0,sizeof(b));
if (dfs(1,1)) {
cout<< B <<endl;
return 0;
}
}
}