using System; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Collections.Generic; using System.Diagnostics; using System.Numerics; using Enu = System.Linq.Enumerable; public class Program { public void Solve() { int H = Reader.Int() + 2, W = Reader.Int() + 2; var grid = Reader.StringArray(H - 2); grid = Surround(grid, '.'); var que = new Queue(); var minDist = new int[H, W]; Fill(minDist, H + W + 10); Func IsInside = (r, c) => r >= 0 && r < H && c >= 0 && c < W; for (int r = 0; r < H; r++) for (int c = 0; c < W; c++) if (grid[r][c] == '.') { que.Enqueue(r); que.Enqueue(c); minDist[r, c] = 0; } while (que.Count > 0) { int r = que.Dequeue(), c = que.Dequeue(); for (int dr = -1; dr <= 1; dr++) for (int dc = -1; dc <= 1; dc++) { int nr = r + dr, nc = c + dc; if (IsInside(nr, nc) && CheckMin(ref minDist[nr, nc], minDist[r, c] + 1)) { que.Enqueue(nr); que.Enqueue(nc); } } } int ans = 0; for (int r = 0; r < H; r++) for (int c = 0; c < W; c++) CheckMax(ref ans, minDist[r, c]); Console.WriteLine(ans); } bool CheckMin(ref int a, int b) { if (b < a) { a = b; return true; } return false; } bool CheckMax(ref int a, int b) { if (b > a) { a = b; return true; } return false; } string[] Surround(string[] grid, char c) { int H = grid.Length + 2, W = grid[0].Length + 2; var res = new string[H]; for (int i = 0; i < H; i++) if (i == 0 || i == H - 1) res[i] = new string(c, W); else res[i] = c + grid[i - 1] + c; return res; } void Fill(T[,] A, T val) { for (int a = 0; a < A.GetLength(0); a++) for (int b = 0; b < A.GetLength(1); b++) A[a, b] = val; } } class Entry { static void Main() { new Program().Solve(); } } class Reader { static TextReader reader = Console.In; static readonly char[] separator = { ' ' }; static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries; static string[] A = new string[0]; static int i; static void Init() { A = new string[0]; } public static void Set(TextReader r) { reader = r; Init(); } public static void Set(string file) { reader = new StreamReader(file); Init(); } public static bool HasNext() { return CheckNext(); } public static string String() { return Next(); } public static int Int() { return int.Parse(Next()); } public static long Long() { return long.Parse(Next()); } public static double Double() { return double.Parse(Next()); } public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); } public static int[] IntArray(int N) { return Range(N, Int); } public static int[][] IntTable(int H) { return Range(H, IntLine); } public static string[] StringArray(int N) { return Range(N, Next); } public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); } public static string Line() { return reader.ReadLine().Trim(); } static string[] Split(string s) { return s.Split(separator, op); } static T[] Range(int N, Func f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; } static string Next() { CheckNext(); return A[i++]; } static bool CheckNext() { if (i < A.Length) return true; string line = reader.ReadLine(); if (line == null) return false; if (line == "") return CheckNext(); A = Split(line); i = 0; return true; } }