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>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;++x)
#define Red(x,y,z) for(int x=y;x>=z;--x)
using namespace std;
const int MAXN=200;
char buf[1<<12],*p1=buf,*p2=buf,nc;int ny;
//inline char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
inline char gc(){return getchar();}
inline int read(){
	int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc;
	x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny;
}int n,m,row[MAXN][MAXN],col[MAXN][MAXN],F[MAXN][MAXN][MAXN],G[MAXN][MAXN][MAXN],ans,cur1[MAXN][MAXN][MAXN],cur2[MAXN][MAXN][MAXN];char s[MAXN][MAXN];
inline void pre(){
	Rep(i,1,n)Red(j,m,1)row[i][j]=(s[i][j]==s[i][j+1]?row[i][j+1]:0)+1;
	Red(i,n,1)Rep(j,1,m)col[i][j]=(s[i][j]==s[i+1][j]?col[i+1][j]:0)+1;
	Rep(i,1,n)Rep(j,1,m){F[i][j][j]=col[i][j];Rep(k,j+1,m)F[i][j][k]=min(F[i][j][k-1],s[i][j]==s[i][k]?col[i][k]:0);}
	Rep(i,1,m)Rep(j,1,n){G[i][j][j]=row[j][i];Rep(k,j+1,n)G[i][j][k]=min(G[i][j][k-1],s[j][i]==s[k][i]?row[k][i]:0);}
}inline void Dp(){
	Rep(i,1,n)Rep(j,1,m)Rep(k,j,m)F[i][j][k]+=F[i+F[i][j][k]][j][k],(F[i][j][k]?cur1[j][i][i+F[i][j][k]-1]=max(cur1[j][i][i+F[i][j][k]-1],k-j+1):0);
	Rep(i,1,m)Rep(j,1,n)Rep(k,j,n)G[i][j][k]+=G[i+G[i][j][k]][j][k],(G[i][j][k]?cur2[j][i][i+G[i][j][k]-1]=max(cur2[j][i][i+G[i][j][k]-1],k-j+1):0);
	Rep(i,1,n)Rep(j,1,m)Red(k,m,j)F[i][j][k]=max(F[i][j][k],max(F[i][j][k+1],cur2[i][j][k]));
	Rep(i,1,m)Rep(j,1,n)Red(k,n,j)G[i][j][k]=max(G[i][j][k],max(G[i][j][k+1],cur1[i][j][k]));
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),m=read();
	Rep(i,1,n)scanf("%s",s[i]+1);
	for(pre(),ans=0;F[1][1][m]<n;ans++,Dp());cout<<ans<<'\n';
	return 0;
}