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>
using namespace std;

template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
template <typename T> void chmin(T &x,const T &y)
{
	if(x>y)x=y;
}
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
const int N=200,A=20;
char s[N][N];
int f[N][N][N],g[N][N][N];

int main()
{
#ifdef kcz
	freopen("1.in","r",stdin);
#endif
	int n,m;
	cin>>n>>m;
	rep(i,1,n)scanf("%s",s[i]+1);
	rep(len,1,n)
	rep(u,1,n-len+1)
	{
		int d=u+len-1;
		f[u][d][m+1]=m;
		per(l,m,1)
		{
			if(len==1)f[u][d][l]=s[u][l]==s[u][l+1]?f[u][d][l+1]:l;
			else f[u][d][l]=(s[u][l]==s[u+1][l]&&f[u+1][d][l]>=l)?
					(s[u][l]==s[u][l+1]?f[u][d][l+1]:l):l-1;
		}
	}
	int ans=0;
while(f[1][n][1]<m)
{
	++ans;
	swap(f,g);
	
	rep(len,1,n)
	rep(u,1,n-len+1)
	{
		int d=u+len-1;
		f[u][d][m+1]=m;
		per(l,m,1)
		{
				f[u][d][l]=g[u][d][g[u][d][l]+1];
				if(f[u][d][l]==m)continue;
				int l1=u,r1=d-1;
				if(len>5)
				while(l1+1!=r1)
				{
					int m=(l1+r1)/2;
					if(g[u][m][l]>=g[m+1][d][l])l1=m;
					else r1=m;
				}
			//	if(u==1&&d==6&&l==1)
			//		int yyx=1;
				rep(i,l1,r1)chmax(f[u][d][l],min(g[u][i][l],g[i+1][d][l]));
		}
	}
}
	cout<<ans;
}