#include #include using namespace std; using namespace atcoder; struct Fast { Fast() { std::cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(10); } } fast; #define all(a) (a).begin(), (a).end() #define contains(a, x) ((a).find(x) != (a).end()) #define rep(i, a, b) for (int i = (a); i < (int)(b); i++) #define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--) #define writejoin(s, a) rep(_i, 0, (a).size()) cout << (a)[_i] << (_i + 1 < (int)(a).size() ? s : "\n"); #define YN(b) cout << ((b) ? "YES" : "NO") << "\n"; #define Yn(b) cout << ((b) ? "Yes" : "No") << "\n"; #define yn(b) cout << ((b) ? "yes" : "no") << "\n"; using ll = long long; using mint = modint998244353; int main() { int h, w; cin >> h >> w; vector s(h); rep(i, 0, h) cin >> s[i]; vector> sum(h + 1, vector(w + 1, 0)); rep(i, 0, h) rep(j, 0, w) sum[i + 1][j + 1] = s[i][j] == '#'; rep(i, 0, h) rep(j, 0, w + 1) sum[i + 1][j] += sum[i][j]; rep(i, 0, h + 1) rep(j, 0, w) sum[i][j + 1] += sum[i][j]; int l = 1, r = min(h, w) + 1; while (r - l > 1) { int m = l + (r - l) / 2; vector> a(h + 1, vector(w + 1, 0)); rep(i, 0, h - m + 1) rep(j, 0, w - m + 1) { if (sum[i + m][j + m] + sum[i][j] - sum[i + m][j] - sum[i][j + m] == m * m) { a[i][j]++; a[i + m][j + m]++; a[i + m][j]--; a[i][j + m]--; } } rep(i, 0, h) rep(j, 0, w) a[i + 1][j] += a[i][j]; rep(i, 0, h) rep(j, 0, w) a[i][j + 1] += a[i][j]; bool ok = true; rep(i, 0, h) rep(j, 0, w) ok &= s[i][j] == '.' || a[i][j] > 0; if (ok) l = m; else r = m; } cout << l << "\n"; }