#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 186;
int n,m;
int sp[MAX][MAX];
int32_t poz[2][MAX][MAX][MAX];
int32_t poz_podz[2][MAX][MAX][MAX];
int32_t pion[2][MAX][MAX][MAX];
int32_t pion_podz[2][MAX][MAX][MAX];
int32_t res[2][MAX][MAX][MAX];

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> m;
  R(i,n){
    string s;
    cin >> s;
    R(j,m){
      sp[i+1][j+1] = sp[i + 1][j] + sp[i][j+1] - sp[i][j] + (s[j] == '.');
    }
  }
  R(_,n + 1){
    int i = _ & 1;
    R(ii,m + 1)for(int j = _ - 1; j >= 0; j--)for(int jj = ii - 1; jj >= 0; jj--){
      int pom = sp[_][ii] - sp[_][jj] - sp[j][ii] + sp[j][jj];
      if(pom == 0 || pom == (_ - j) * (ii - jj)){
       // debug("pusty", _, ii, j, jj);
        poz[i][ii][j][jj] = 0;
        poz_podz[i][ii][j][jj] = j;
        pion[i][ii][j][jj] = 0;
        pion_podz[i][ii][j][jj] = jj;
        res[i][ii][j][jj] = 0;
        continue;
      }
      
      int32_t &pozz = poz[i][ii][j][jj];
      
      if(j + 1 != _){
        pozz = 1 + max(res[!i][ii][j][jj], res[i][ii][_-1][jj]);
        poz_podz[i][ii][j][jj] = _ - 1;
      }else{
        pozz = 1e9;
        poz_podz[i][ii][j][jj] = _;
      }
      
      
      int32_t war = poz[!i][ii][j][jj];
      int32_t gd = poz_podz[!i][ii][j][jj];
      if(res[i][ii][gd][jj] < war){
        if(pozz > war){
          pozz = war;
          poz_podz[i][ii][j][jj] = gd;
        }
      }
      
      
      int32_t &pionn = pion[i][ii][j][jj];
      
      
      if(jj + 1 != ii){
        pionn = 1 + max(res[i][ii-1][j][jj], res[i][ii][j][ii-1]);
        pion_podz[i][ii][j][jj] = ii - 1;
      }else{
        pionn = 1e9;
        pion_podz[i][ii][j][jj] = ii;
      }
      
      
      
      war = pion[i][ii-1][j][jj];
      gd = pion_podz[i][ii-1][j][jj];
      if(res[i][ii][j][gd] < war) {
        if(pionn > war){
          pionn = war;
          pion_podz[i][ii][j][jj] = gd;
        }
      }
      res[i][ii][j][jj] = min(pionn, pozz);
        
    }
  }
  cout << res[n&1][m][0][0] << "\n";
}


Measured memory_bytes: 251776