#include #include #include #include #include int main() { using namespace std; int h, w; cin >> h >> w; vector s(h); for (auto &e : s) { cin >> e; } vector dist(h + 2, vector(w + 2, -1)); queue> que; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (s[i][j] == '.') { dist[i + 1][j + 1] = 0; que.emplace(i + 1, j + 1); } } } for (int i = 0; i < h + 2; i++) { dist[i][0] = 0; que.emplace(i, 0); dist[i][w + 1] = 0; que.emplace(i, w + 1); } for (int j = 0; j < w + 2; j++) { dist[0][j] = 0; que.emplace(0, j); dist[h + 1][j] = 0; que.emplace(h + 1, j); } constexpr int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1}; constexpr int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1}; int ans = 0; while (!que.empty()) { auto [x, y] = que.front(); que.pop(); ans = max(ans, dist[x][y]); for (int i = 0; i < 8; i++) { int nx = x + dx[i], ny = y + dy[i]; if (nx < 0 || nx > h + 1 || ny < 0 || ny > w + 1) { continue; } if (dist[nx][ny] == -1) { dist[nx][ny] = dist[x][y] + 1; que.emplace(nx, ny); } } } cout << ans << endl; }