#include using namespace std; const int INF = 1e6; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int H, W; cin >> H >> W; W += 2; vector bd; bd.push_back(string(W, '.')); for (int i = 0; i < H; i++) { string tmp; cin >> tmp; tmp = "." + tmp + "."; bd.push_back(tmp); } bd.push_back(string(W, '.')); H += 2; vector > dist(H, vector(W, INF)); queue > q; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (bd[i][j] == '.') { q.emplace(i, j); dist[i][j] = 0; } } } while (!q.empty()) { int y, x; tie(y, x) = q.front(); q.pop(); for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { int yt = y + i; int xt = x + j; if (xt < 0 || xt >= W) continue; if (yt < 0 || yt >= H) continue; if (dist[yt][xt] == INF) { q.emplace(yt, xt); dist[yt][xt] = dist[y][x] + 1; } } } } int ret = 0; for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) ret = max(ret, dist[i][j]); cout << ret << endl; return 0; }