import std.stdio; import std.array; import std.string; import std.conv; import std.algorithm; import std.typecons; import std.range; import std.random; import std.math; import std.container; void main() { auto input = readln.split.map!(to!int); int H = input[0]; int W = input[1]; auto B = new string[](H+2); B[0] = replicate(".", W+2); foreach (i; iota(1, H+1)) B[i] = "." ~ readln.chomp ~ "."; B[H+1] = replicate(".", W+2); DList!(Tuple!(int, int, int)) queue; foreach (i; iota(H+2)) foreach (j; iota(W+2)) if (B[i][j] == '.') queue.insert(tuple(i, j, 0)); bool[int][int] visited; int ans = 0; int r, c, depth, nr, nc; int[8] dx = [-1, 0, 1, -1, 1, -1, 0, 1]; int[8] dy = [-1, -1, -1, 0, 0, 1, 1, 1]; while (!queue.empty) { auto node = queue.front; r = node[0]; c = node[1]; depth = node[2]; queue.removeFront; if (r in visited && c in visited[r]) continue; ans = max(ans, depth); visited[r][c] = true; foreach (d; iota(8)) { nr = r + dx[d]; nc = c + dy[d]; if (nr < 0 || nr >= H+2 || nc < 0 || nc >= W+2) continue; if (nr in visited && nc in visited[nr]) continue; queue.insert(tuple(nr, nc, depth+1)); } } writeln(ans); }