#include using namespace std; int main() { int h, w; cin >> h >> w; vector g(h + 2, string(w + 2, '.')); for (int i = 0; i < h; i++) { string s; cin >> s; for (int j = 0; j < w; j++) { g[i + 1][j + 1] = s[j]; } } h += 2; w += 2; vector> dist(h, vector(w, -1)); queue> q; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (g[i][j] != '#') { dist[i][j] = 0; q.emplace(i, j); } } } while (!q.empty()) { int y, x; tie(y, x) = q.front(); q.pop(); const int dy[] = { 0, 0, 1, 1, 1, -1, -1, -1 }; const int dx[] = { 1, -1, 1, 0, -1, 1, 0, -1 }; for (int k = 0; k < 8; k++) { int ny = y + dy[k]; int nx = x + dx[k]; if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue; if (dist[ny][nx] == -1) { dist[ny][nx] = dist[y][x] + 1; q.emplace(ny, nx); } } } int maxi = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { maxi = max(maxi, dist[i][j]); } } cout << maxi << endl; }