using System;
using System.Linq;
using System.Collections.Generic;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            AGC033.A();
        }

        class AGC033
        {
            public static void A()
            {
                var H = Read.Int();
                var W = Read.Int();
                var A = new bool[H + 2, W + 2];
                Queue<Tuple<int, int>> queue = new Queue<Tuple<int, int>>();
                for(int i = 1; i <= H; ++i)
                {
                    var str = Read.Str();
                    for (int j = 0; j < W; ++j)
                    {
                        A[i, j + 1] = str[j] == '.';
                        if (str[j] == '#')
                        {
                            queue.Enqueue(new Tuple<int, int>(i, j + 1));
                        }
                    }
                }
                var distMax = 0;
                var dist = new int[H + 2, W + 2];
                for(int i = 0; i < H + 2; ++i)
                {
                    for(int j = 0; j < W + 2; ++j)
                    {
                        dist[i, j] = A[i, j] ? -1 : 0;
                    }
                }
                var dx = new int[] { 1, 0, -1, 0 };
                var dy = new int[] { 0, 1, 0, -1 };
                while (queue.Count > 0)
                {
                    var t = queue.Dequeue();
                    for(int i = 0; i < 4; ++i)
                    {
                        var x = t.Item1 + dx[i];
                        var y = t.Item2 + dy[i];
                        if (dist[x, y] < 0)
                        {
                            dist[x, y] = dist[t.Item1, t.Item2] + 1;
                            distMax = Math.Max(distMax, dist[x, y]);
                            queue.Enqueue(new Tuple<int, int>(x, y));
                        }
                    }
                }
                Console.WriteLine(distMax);
            }
            public static void B()
            {
                var H = Read.Int();
                var W = Read.Int();
                var N = Read.Int();
                var SR = Read.Int();
                var SC = Read.Int();
                var S = Read.Str();
                var T = Read.Str();
                {
                    int idx1 = 0;
                    int idx2 = H;
                    for(int i = N - 1; i >= 0; --i)
                    {
                        switch (T[i])
                        {
                            case 'U': idx2 = Math.Min(H, idx2 + 1); break;
                            case 'D': idx1 = Math.Max(0, idx1 - 1); break;
                        }
                        switch (S[i])
                        {
                            case 'U': idx1++; break;
                            case 'D': idx2--; break;
                        }
                        if (idx1 == idx2) { Console.WriteLine("NO"); return; }
                    }
                    if(idx1>=SR || idx2 < SR) { Console.WriteLine("NO"); return; }
                }
                {
                    int idx1 = 0;
                    int idx2 = W;
                    for (int i = N - 1; i >= 0; --i)
                    {
                        switch (T[i])
                        {
                            case 'L': idx2 = Math.Min(W, idx2 + 1); break;
                            case 'R': idx1 = Math.Max(0, idx1 - 1); break;
                        }
                        switch (S[i])
                        {
                            case 'L': idx1++; break;
                            case 'R': idx2--; break;
                        }
                        if (idx1 == idx2) { Console.WriteLine("NO"); return; }
                    }
                    if (idx1 >= SC || idx2 < SC) { Console.WriteLine("NO"); return; }
                }
                Console.WriteLine("YES");
            }
            public static void C()
            {
                var N = Read.Int();
                var Adj = Read.AdjacencyList(N, N - 1);
                var dist1 = Util.CalcDistance_OnTree(Adj, N, 1);
                var max = dist1.Max();
                var dist2 = Util.CalcDistance_OnTree(Adj, N, Enumerable.Range(1, N).Where(i => dist1[i] == max).First());
                var d = dist2.Max();
                Console.WriteLine(d % 3 != 1 ? "First" : "Second");
            }
        }


        class Util
        {
            public static int[] CalcDistance_OnTree(Dictionary<int, HashSet<int>> adj, int N, int start)
            {
                var dist = Enumerable.Range(0, N + 1).Select(i => -1).ToArray();
                dist[start] = 0;
                Queue<int> queue = new Queue<int>();
                queue.Enqueue(start);
                while (queue.Count > 0)
                {
                    var v = queue.Dequeue();
                    foreach (var w in adj[v])
                    {
                        if (dist[w] < 0)
                        {
                            dist[w] = dist[v] + 1;
                            queue.Enqueue(w);
                        }
                    }
                }
                return dist;
            }
        }

        static class Read
        {
            static Queue<string> queue = new Queue<string>();
            static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } }
            public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); }
            public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); }
            public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); }
            public static int[] IntN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); }
            public static long[] LongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); }
            public static string[] StrN() { return Console.ReadLine().Split(' '); }
            public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); }
            public static long[,] LongMatrix(int r, int c)
            {
                var mat = new long[r, c];
                for (int i = 0; i < r; ++i)
                {
                    var x = Read.LongN();
                    for (int j = 0; j < c; ++j)
                    {
                        mat[i, j] = x[j];
                    }
                }
                return mat;
            }
            public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M)
            {
                Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
                for (int i = 0; i <= N; ++i)
                {
                    dict.Add(i, new HashSet<int>());
                }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN();
                    dict[ab[0]].Add(ab[1]);
                    dict[ab[1]].Add(ab[0]);
                }
                return dict;
            }
            public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M)
            {
                Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>();
                for (int i = 0; i <= N; ++i)
                {
                    dict.Add(i, new Dictionary<int, long>());
                }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN();
                    dict[ab[0]].Add(ab[1], ab[2]);
                    dict[ab[1]].Add(ab[0], ab[2]);
                }
                return dict;
            }
        }
    }
}


Measured memory_bytes: 54460