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:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
typedef unsigned char uc;
const ll MAX_H=185,MAX_W=185,MAX_LOG_HW=16;
int H,W;
string A[MAX_H];
uc dpw[MAX_H][MAX_H+1][MAX_W+1][MAX_LOG_HW+1],dph[MAX_W][MAX_W+1][MAX_H+1][MAX_LOG_HW+1];
bool cmp(ll i1,ll i2,ll j1,ll j2,ll k){
	//complexityがk以下かどうか
	ll w=dpw[i1][i2][j1][k-1];
	if(w+dpw[i1][i2][j1+w][k-1]>=j2-j1){
		return true;
	}
	ll h=dph[j1][j2][i1][k-1];
	if(h+dph[j1][j2][i1+h][k-1]>=i2-i1){
		return true;
	}
	return false;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>H>>W;
	REP(i,H)cin>>A[i];
	for(ll i=H-1;i>=0;i--)for(ll j=W-1;j>=0;j--){
		if(j<W-1&&A[i][j]==A[i][j+1])dpw[i][i+1][j][0]=dpw[i][i+1][j+1][0]+1;
		else dpw[i][i+1][j][0]=1;
		if(i<H-1&&A[i][j]==A[i+1][j])dph[j][j+1][i][0]=dph[j][j+1][i+1][0]+1;
		else dph[j][j+1][i][0]=1;
	}
	REP(i1,H){
		FOR(i2,i1+2,H+1){
			REP(w,W){
				if(dph[w][w+1][i1][0]>=i2-i1){
					dpw[i1][i2][w][0]=min(dpw[i1][i2-1][w][0],dpw[i2-1][i2][w][0]);
				}else{
					dpw[i1][i2][w][0]=0;
				}
			}
		}
	}
	REP(i1,W){
		FOR(i2,i1+2,W+1){
			REP(h,H){
				if(dpw[h][h+1][i1][0]>=i2-i1){
					dph[i1][i2][h][0]=min(dph[i1][i2-1][h][0],dph[i2-1][i2][h][0]);
				}else{
					dph[i1][i2][h][0]=0;
				}
			}
		}
	}
	FOR(k,1,MAX_LOG_HW+1){
		REP(i1,H){
			FOR(i2,i1+1,H+1){
				ll j2=0;
				REP(j1,W){
					while(j2<W&&cmp(i1,i2,j1,j2,k))j2++;
					if(!cmp(i1,i2,j1,j2,k)){
						j2--;
					}
					dpw[i1][i2][j1][k]=j2-j1;
					if(j2==j1)j2++;
				}
			}
		}
		REP(j1,W){
			FOR(j2,j1+1,W+1){
				ll i2=0;
				REP(i1,H){
					while(i2<H&&cmp(i1,i2,j1,j2,k))i2++;
					if(!cmp(i1,i2,j1,j2,k)){
						i2--;
					}
					dph[j1][j2][i1][k]=i2-i1;
					if(i2==i1)i2++;
				}
			}
		}
	}
	ll ans=0;
	REP(k,MAX_LOG_HW+1){
		if(dpw[0][H][0][k]>=W||dph[0][W][0][k]>=H){cout<<k<<endl;break;}
	}
//	cout<<dpw[0][H-1][0][0]<<endl;
}