#include <bits/stdc++.h>
using namespace std;

#define forn(i,n) for (int i = 0; i < int(n); i++)
#define get __nico_get

typedef long long ll;


const int N = 200;

int n,m, cum[N][N], hdp[2][N][N][N], vdp[2][N][N][N];
string a[N];

int get(int i1, int i2, int j1, int j2) {
    return cum[i2][j2] - cum[i1][j2] - cum[i2][j1] + cum[i1][j1];
}

int solve() {
    int prev = 0, cur = 1;
    for (int comp = 1; comp < N; comp++) {
        if (hdp[prev][0][n][0] == m) return comp-1;

        for (int i1 = 0; i1 <= n; i1++) {
            for (int i2 = i1; i2 <= n; i2++) {
                for (int j1 = 0; j1 <= m; j1++) {
                    int jump = hdp[prev][i1][i2][j1];
                    int njump = hdp[prev][i1][i2][jump];
                    hdp[cur][i1][i2][j1] = njump;
                }
            }
        }

        for (int j1 = 0; j1 <= m; j1++) {
            for (int j2 = j1; j2 <= m; j2++) {
                for (int i1 = 0; i1 <= n; i1++) {
                    int jump = vdp[prev][j1][j2][i1];
                    int njump = vdp[prev][j1][j2][jump];
                    vdp[cur][j1][j2][i1] = njump;
                }
            }
        }

        for (int i1 = 0; i1 <= n; i1++) {
            for (int i2 = i1; i2 <= n; i2++) {
                for (int j1 = 0; j1 <= m; j1++) {
                    int lo = j1, hi = m+1;
                    while (lo+1 < hi) {
                        int mi = (lo+hi)/2;
                        if (vdp[cur][j1][mi][i1] >= i2) lo = mi; else hi = mi;
                    }
                    hdp[cur][i1][i2][j1] = max(hdp[cur][i1][i2][j1], lo);
                }
            }
        }

        for (int j1 = 0; j1 <= m; j1++) {
            for (int j2 = j1; j2 <= m; j2++) {
                for (int i1 = 0; i1 <= n; i1++) {
                    int lo = i1, hi = n+1;
                    while (lo+1 < hi) {
                        int mi = (lo+hi)/2;
                        if (hdp[cur][i1][mi][j1] >= j2) lo = mi; else hi = mi;
                    }
                    vdp[cur][j1][j2][i1] = max(vdp[cur][j1][j2][i1], lo);
                }
            }
        }

        swap(prev, cur);
    }
}

bool good(int i1, int i2, int j1, int j2) {
    auto s = get(i1,i2,j1,j2);
    auto area = (i2-i1) * (j2-j1);
    return s == 0 || s == area;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n >> m;
    forn(i,n) cin >> a[i];
    forn(i,n) forn(j,m) {
        cum[i+1][j+1] = 
            + cum[i][j+1] 
            + cum[i+1][j] 
            - cum[i][j] 
            + (a[i][j] == '#');
    }

    for (int i1 = 0; i1 <= n; i1++) {
        for (int i2 = i1; i2 <= n; i2++) {
            int j2 = 0;
            for (int j1 = 0; j1 <= m; j1++) {
                j2 = max(j1, j2);
                while (j2 <= m && good(i1,i2,j1,j2)) j2++;
                hdp[0][i1][i2][j1] = j2-1;
            }
        }
    }

    for (int j1 = 0; j1 <= m; j1++) {
        for (int j2 = j1; j2 <= m; j2++) {
            int i2 = 0;
            for (int i1 = 0; i1 <= n; i1++) {
                i2 = max(i1, i2);
                while (i2 <= n && good(i1,i2,j1,j2)) i2++;
                vdp[0][j1][j2][i1] = i2-1;
            }
        }
    }
    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 123136