#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
 
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gpu_hash_map<int, int> mp;*/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = -1e6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 185;
int h, w;
int board[mxN][mxN];
int psum[mxN][mxN];
int dph[mxN][mxN][mxN];
int dpv[mxN][mxN][mxN];
int gt(int x1, int y1, int x2, int y2) {
    return psum[x2+1][y2+1] - psum[x1][y2+1] - psum[x2+1][y1] + psum[x1][y1];
}
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>h>>w;
    string s;
    owo(i, 0, h) {
        cin>>s;
        owo(j, 0, w) {
            board[i][j] = (s[j]=='#');
        }
    }
    owo(i, 0, h) {
        owo(j, 0, w) {
            psum[i+1][j+1] = psum[i+1][j] + psum[i][j+1] - psum[i][j] + board[i][j];
        }
    }
    owo(i, 0, h) {
        owo(j, i, h) {
            owo(k, 0, w) {
                int l = 0;
                int r = k+1;
                while(l<r) {
                    int mid = (l+r)/2;
                    int nn = gt(i, mid, j, k);
                    if(nn==(j-i+1)*(k-mid+1)||nn==0)r = mid;
                    else l = mid+1;
                }
                dpv[i][j][k] = l;
            }
        }
    }
    owo(i, 0, w) {
        owo(j, i, w) {
            owo(k, 0, h) {
                int l = 0;
                int r = k+1;
                while(l<r) {
                    int mid = (l+r)/2;
                    int nn = gt(mid, i, k, j);
                    if(nn==(j-i+1)*(k-mid+1)||nn==0)r = mid;
                    else l = mid+1;
                }
                dph[i][j][k] = l;
            }
        }
    }
    int ans = 0;
    while(dpv[0][h-1][w-1]>0) {
        ans++;
        owo(i, 0, h) {
            owo(j, i, h) {
                uwu(k, w, 0) {
                    if(dpv[i][j][k]>0) dpv[i][j][k] = dpv[i][j][dpv[i][j][k]-1];
                }
            }
        }
        owo(i, 0, w) {
            owo(j, i, w) {
                uwu(k, h, 0) {
                    if(dph[i][j][k]>0) dph[i][j][k] = dph[i][j][dph[i][j][k]-1];
                    int l = 0;
                    int r = dph[i][j][k];
                    while(l<r) {
                        int mid = (l+r)/2;
                        if(dpv[mid][k][j]<=i)r = mid;
                        else l = mid+1;
                    }
                    dph[i][j][k] = l;
                }
            }
        }
        owo(i, 0, h) {
            owo(j, i, h) {
                uwu(k, w, 0) {
                    int l = 0;
                    int r = dpv[i][j][k];
                    while(l<r) {
                        int mid = (l+r)/2;
                        if(dph[mid][k][j]<=i)r = mid;
                        else l = mid+1;
                    }
                    dpv[i][j][k] = l;
                }
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 30208