#include #include #define maxn 2000 int n, m; char a[maxn + 5][maxn + 5]; int sum[maxn + 5][maxn + 5], tmp[maxn + 5][maxn + 5]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%s", a[i] + 1); for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) sum[i][j] = sum[i][j - 1] + sum[i - 1][j] - sum[i - 1][j - 1] + (a[i][j] == '#'); int L = 1, R = std::min(n, m); for (; L < R; ) { int mid = (L + R + 1) >> 1; for (int i = 1; i + mid - 1 <= n; ++i) for (int j = 1; j + mid - 1 <= m; ++j) { int _i = i + mid - 1, _j = j + mid - 1; int cnt = sum[_i][_j] - sum[_i][j - 1] - sum[i - 1][_j] + sum[i - 1][j - 1]; if (cnt == mid * mid) ++tmp[i][j], --tmp[i][_j + 1], --tmp[_i + 1][j], ++tmp[_i + 1][_j + 1]; } bool res = true; for (int i = 1; i <= n && res; ++i) for (int j = 1; j <= m && res; ++j) { tmp[i][j] = tmp[i][j - 1] + tmp[i - 1][j] - tmp[i - 1][j - 1] + tmp[i][j]; if ((tmp[i][j] > 0 && a[i][j] == '.') || (tmp[i][j] == 0 && a[i][j] == '#')) res = false; } if (res) L = mid; else R = mid - 1; } printf("%d", L); return 0; }