#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned ui;
typedef unsigned long long ul;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef pair<ul, ul> puu;
typedef vector<int> vi;
#define pb push_back
#define fi first
#define se second
#define ls (i << 1)
#define rs (i << 1 | 1)
#define mid (l + r >> 1)
#define enum(i, j, k) for(int i = j; i <= (k); i ++)
#define open(i, j, k) for(int i = j; i <  (k); i ++)
#define dec(i, j, k)  for(int i = j; i >= (k); i --)
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
#define mfil(x, k) memset(x, k, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
#define fio(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout)
template <class T> bool chkmin(T &x, T y)
{ return y < x ? (x = y, true) : false; }
template <class T> bool chkmax(T &x, T y)
{ return y > x ? (x = y, true) : false; }
struct __init { __init()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cout.precision(16); cout << fixed;
    srand(time(0) ^ ui(ul(new char)));
} } static __init__;
/* default code ends here */

const int maxn = 190;
int n, m;
bool a[maxn][maxn];
int sum[maxn][maxn];
bool pure(int x1, int y1, int x2, int y2)
{
    //cerr << "P : " << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << ' ';
    x1 --;
    y1 --;
    int d = sum[x2][y2] - sum[x1][y2] - sum[x2][y1] + sum[x1][y1];
    //cerr << (d == 0 || d == (x2 - x1) * (y2 - y1)) << endl;
    return d == 0 || d == (x2 - x1) * (y2 - y1);
}

int dp[2][maxn][maxn][maxn];
int pos[maxn];

bool cur;

int f(int i, int j, int k, int t)
{
    return min(dp[!cur][i][j][t], dp[!cur][i][t + 1][k]);
}

int main()
{
    cin >> n >> m;
    string foo;
    enum(i, 1, n)
    {
        cin >> foo;
        enum(j, 1, m)
            a[i][j] = foo[j - 1] == '#';
    }
    enum(i, 1, n)
        enum(j, 1, m)
            sum[i][j] = a[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];

    cur = false;
    enum(i, 1, n)
        enum(j, 1, m)
        {
            int val = i - 1;
            dec(k, m, j)
            {
                for( ; val < n && pure(i, j, val + 1, k); val ++) ;
                //cerr << i << ' ' << j << ' ' << k << ' ' << val << endl;
                dp[cur][i][j][k] = val;
            }
        }
    
    /*enum(i, 1, n)
    {
        enum(j, 1, m)
            cerr << dp[cur][i][j][m] << ' ';
        cerr << endl;
    }
    cerr << endl;*/

    //exit(0);
    
    int ans = 0;
    while(true)
    {
        if(dp[cur][1][1][m] == n)
            break;
        cur = !cur;
        mfil(dp[cur], 0);
        enum(i, 1, n)
            enum(j, 1, m)
                enum(k, j, m)
                {
                    if(dp[!cur][i][j][k] == n)
                        dp[cur][i][j][k] = n;
                    else
                        dp[cur][i][j][k] = dp[!cur][dp[!cur][i][j][k] + 1][j][k];
                }
        
        /*enum(i, 1, n)
        {
            enum(j, 1, m)
                cerr << dp[cur][i][j][2] << ' ';
            cerr << endl;
        }
        cerr << endl;*/

        
        enum(i, 1, n)
        {
            enum(j, 1, m)
                pos[j] = j;
            enum(len, 2, m)
            {
                enum(j, 1, m - len + 1)
                {
                    int k = j + len - 1;
                    for( ; pos[j] + 1 < k && f(i, j, k, pos[j] + 1) >= f(i, j, k, pos[j]); pos[j] ++) ;//cerr << pos[j] << '\n';
                    //cerr << i << ' ' << j << ' ' << k << ' ' << pos[j] << endl;
                    chkmax(dp[cur][i][j][k], f(i, j, k, pos[j]));
                }
                /*enum(j, 1, m)
                    cerr << pos[j] << ' ';
                cerr << endl;*/
            }
            //cerr << endl;
        }
            
                
        /*enum(i, 1, n)
        {
            enum(j, 1, m)
                cerr << dp[cur][i][j][m] << ' ';
            cerr << endl;
        }
        cerr << endl;*/
        ans ++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 54016