#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int n,m;
int a[101][101],b[101][101];
int ans;
void init(){
int i,j;
char ch;
cin>>n>>m;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++){
cin>>ch;
if (ch=='R') a[i][j]=1;
else a[i][j]=0;
}
}
bool judge(int r){
int i,j,i2,j2;
memset(b,0,sizeof(b));
i=1;j=1;
while (j<=m-r+1){
if (b[i][j]!=a[i][j]){
for (i2=i;i2<=i+r-1;i2++)
for (j2=j;j2<=j+r-1;j2++)
b[i2][j2]=a[i][j];
}
if (i<n-r+1) i++;
else {
j++;
i=1;
}
}
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
if (a[i][j]!=b[i][j]) return false;
return true;
}
void solve(){
int i;
ans=min(n,m);
while (ans>0){
if (judge(ans)) {
printf("%d\n",ans);
return;
}
ans--;
}
}
int main(){
freopen("skicourse.in","r",stdin);
freopen("skicourse.out","w",stdout);
init();
solve();
return 0;
}