#include<cstdio>
#include<cstring>
#define N 190
inline int min(int x,int y){return x<y?x:y;}
inline int max(int x,int y){return x<y?y:x;}
int a[N][N][N],b[N],d[N][N],e[N],f[N][N][N],i,j,k,l,m,n,r,s;char c[N][N];
int main()
{
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)scanf("%s",c[e[i]=i]+1);
	for(i=1;i<=n;i++)for(j=1;j<=m;j++)d[i][j]=d[i][j-1]+(c[i][j]=='.');
	for(i=1;i<=m;i++)for(j=i;j<=m;j++)for(k=1,l=0,a[i][j][n+1]=n;k<=n;a[i][j][k++]=l)while(l<n&&(l+1<k||l+1==k&&(d[l+1][j]-d[l+1][i-1]==j-i+1||d[l+1][j]==d[l+1][i-1])||k<=l&&d[l+1][j]-d[l+1][i-1]==d[l][j]-d[l][i-1]))l++;
	for(s=0;a[1][m][1]<n;s++)
	{
		for(k=1;k<=n;k++)for(memcpy(b+1,e+1,m<<2),j=0;j<m;j++)for(i=1;i+j<=m;f[i][i+j][k]=max(a[i][i+j][a[i][i+j][k]+1],min(a[i][b[i]][k],a[b[i]+1][i+j][k])),i++)while(b[i]<i+j&&min(a[i][b[i]+1][k],a[b[i]+2][i+j][k])>=min(a[i][b[i]][k],a[b[i]+1][i+j][k]))b[i]++;
		for(i=1;i<=m;i++)for(j=i;j<=m;j++)for(k=1;k<=n;k++)a[i][j][k]=f[i][j][k];
	}
	return 0*printf("%d\n",s);
}