Problem: Note the unusual memory limit.

For a rectangular grid where each square is painted white or black, we define its complexity as follows:

* If all the squares are black or all the squares are white, the complexity is 0.
* Otherwise, divide the grid into two subgrids by a line parallel to one of the sides of the grid, and let c_1 and c_2 be the complexities of the subgrids. There can be multiple ways to perform the division, and let m be the minimum value of \max(c_1, c_2) in those divisions. The complexity of the grid is m+1.



You are given a grid with H horizontal rows and W vertical columns where each square is painted white or black. HW characters from A_{11} to A_{HW} represent the colors of the squares. A_{ij} is `#` if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is `.` if that square is white.

Find the complexity of the given grid.

Constraints

* 1 \leq H,W \leq 185
* A_{ij} is `#` or `.`.

Input

Input is given from Standard Input in the following format:


H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}


Output

Print the complexity of the given grid.

Examples

Input

3 3
...
.##
.##


Output

2


Input

6 7
.####.#
....#.
....#.
....#.
.####.#
....##


Output

4

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
typedef long long ll;
#define rep(x,l,r) for(int x=(l),___r=(r);x<=___r;++x)
#define dep(x,r,l) for(int x=(r),___l=(l);x>=___l;--x)
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
int f[190][190][190],g[190][190][190],_f[190][190][190];
char map[190][190];
int Sx[190][190],Sy[190][190];
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi(),m=gi();
	rep(i,1,n)scanf("%s",map[i]+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j){
			Sx[i][j]=Sx[i-1][j]+(map[i-1][j]!=map[i][j]);
			Sy[i][j]=Sy[i][j-1]+(map[i][j-1]!=map[i][j]);
		}
	dep(i,n,1)rep(j,1,m)rep(k,j,m)f[i][j][k]=(Sy[i][j]==Sy[i][k]?map[i][j]==map[i+1][j]?f[i+1][j][k]:i:i-1);
	dep(i,m,1)rep(j,1,n)rep(k,j,n)g[i][j][k]=(Sx[j][i]==Sx[k][i]?map[j][i]==map[j][i+1]?g[i+1][j][k]:i:i-1);
	for(int _=0;;++_){
		if(f[1][1][m]==n||g[1][1][n]==m)printf("%d\n",_),exit(0);
		//update f->g;g->f
		memcpy(_f,f,sizeof f);
		rep(i,1,m)rep(j,1,n)rep(k,j,n)cxk(f[j][i][g[i][j][k]],k);
		rep(i,1,n)rep(j,1,m)rep(k,j,m)cxk(g[j][i][_f[i][j][k]],k);
		rep(i,1,n)rep(j,1,m)dep(k,m,j)cxk(f[i][j][k],f[i][j][k+1]);
		rep(i,1,m)rep(j,1,n)dep(k,n,j)cxk(g[i][j][k],g[i][j][k+1]);
		rep(i,1,n)rep(j,1,m)rep(k,1,m)if(f[i][j][k]<n)f[i][j][k]=f[f[i][j][k]+1][j][k];
		rep(i,1,m)rep(j,1,n)rep(k,1,n)if(g[i][j][k]<m)g[i][j][k]=g[g[i][j][k]+1][j][k];
	}
	return 0;
}