using System; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters; using System.Collections; using System.Collections.Generic; using System.Linq; class Program { static int H, W; static int[,] S; static int[] tate = { -1, 0, 1, -1, 1, -1, 0, 1 }, yoko = { -1, -1, -1, 0, 0, 1, 1, 1 }; static void Main() { int[] q = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); H = q[0]; W = q[1]; Queue Q = new Queue(); S = new int[H + 2, W + 2]; for (int i = 0; i < W + 2; i++) { S[0, i] = 0; Q.Enqueue(new XY(0, i)); S[H + 1, i] = 0; Q.Enqueue(new XY(H + 1, i)); } for (int i = 0; i < H; i++) { string qw = Console.ReadLine(); for (int j = 0; j < W + 2; j++) { if (j == 0 || j == W + 1 || qw[j - 1] == '.') { S[i + 1, j] = 0; Q.Enqueue(new XY(i + 1, j)); } else { S[i + 1, j] = -1; } } } while (Q.Count > 0) { XY xy = Q.Dequeue(); for(int i = 0; i < 8; i++) { if (tate[i] + xy.Y >= 0 && tate[i] + xy.Y <= H + 1 && yoko[i] + xy.X >= 0 && yoko[i]+xy.X <= W + 1) { if (S[tate[i] + xy.Y, yoko[i] + xy.X] == -1) { S[tate[i] + xy.Y, yoko[i] + xy.X] = S[xy.Y, xy.X] + 1; Q.Enqueue(new XY(tate[i] + xy.Y, yoko[i] + xy.X)); } } } } int max = int.MinValue; for(int i= 1;i<= H; i++) { for(int j = 1; j <= W; j++) { max = Math.Max(max, S[i, j]); } } Console.WriteLine(max); } } public struct XY { public XY(int y,int x) { this.X = x; this.Y = y; } public int Y { get; set; } public int X { get; set; } }