#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template ostream &operator<<(ostream &os, const vector &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } int M, N; char A[2010][2010]; int S[2010][2010]; int get(int x0, int x1, int y0, int y1) { return S[x0][y0] - S[x0][y1] - S[x1][y0] + S[x1][y1]; } int f[2010][2010]; bool check(int k) { for (int x = 0; x <= M - k; ++x) for (int y = 0; y <= N - k; ++y) { f[x + 1][y + 1] = f[x + 1][y] + f[x][y + 1] - f[x][y] + (get(x, x + k, y, y + k) ? 0 : 1); } for (int x = 0; x < M; ++x) for (int y = 0; y < N; ++y) if (A[x][y] == '#') { int x0 = x - k + 1, x1 = x + 1; int y0 = y - k + 1, y1 = y + 1; chmax(x0, 0); chmin(x1, M - k + 1); chmax(y0, 0); chmin(y1, N - k + 1); if (f[x0][y0] - f[x0][y1] - f[x1][y0] + f[x1][y1] == 0) { return false; } } return true; } int main() { for (; ~scanf("%d%d", &M, &N); ) { for (int x = 0; x < M; ++x) { scanf("%s", A[x]); } for (int x = 0; x < M; ++x) for (int y = 0; y < N; ++y) { S[x + 1][y + 1] = S[x + 1][y] + S[x][y + 1] - S[x][y] + ((A[x][y] == '.') ? 1 : 0); } int lo = 0, hi = min(M, N) + 1; for (; lo + 1 < hi; ) { const int mid = (lo + hi) / 2; (check(mid) ? lo : hi) = mid; } printf("%d\n", lo); } return 0; }