#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; int dp1[2010][2010]; int dp2[2010][2010]; } int main() { ios::sync_with_stdio(false); cin.tie(0); int h, w; cin >> h >> w; vector s(h); rep(i, h) cin >> s[i]; for(int i = 1; i <= h; i++) { for(int j = 1; j <= w; j++) { if (s[i-1][j-1] == '.') continue; dp1[i][j] = min({dp1[i-1][j], dp1[i][j-1], dp1[i-1][j-1]}) + 1; } } int l = 0, r = 2010; while(r - l > 1) { int c = (l + r) / 2; rep(i, h + 1) rep(j, w + 1) dp2[i][j] = 0; rep(i, h + 1) rep(j, w + 1) if (dp1[i][j] >= c) { dp2[i-c][j-c]++; dp2[i-c][j]--; dp2[i][j-c]--; dp2[i][j]++; } rep(i, h) rep(j, w) dp2[i+1][j] += dp2[i][j]; rep(i, h) rep(j, w) dp2[i][j+1] += dp2[i][j]; bool ok = [&]() -> bool { rep(i, h) rep(j, w) if (s[i][j] == '#' && !dp2[i][j]) { return false; } return true; }(); (ok ? l : r) = c; } cout << l << '\n'; }