using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    struct Index
    {
        public int i;
        public int j;
        public Index(int i, int j)
        {
            this.i = i;
            this.j = j;
        }
    }
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt32();
            var H = line[0];
            var W = line[1];
            var HW = H * W;
            var board = new int[H, W];


            var resultCount = 0;
            var result = new List<List<Index>>();
            result.Add(new List<Index>());

            for (int i = 0; i < H; i++)
            {
                var masu = consoleReader.String();
                for (int j = 0; j < W; j++)
                {
                    if (masu[j] == '#')
                    {
                        board[i, j] = 0;
                        result[0].Add(new Index(i, j));
                        resultCount++;
                    }
                    else
                    {
                        board[i, j] = int.MaxValue;
                    }
                }
            }

            for (int count = 0; ; count++)
            {
                var next = count + 1;
                result.Add(new List<Index>());
                foreach (var index in result[count])
                {
                    var i = index.i;
                    var j = index.j;
                    if (i > 0 && board[i - 1, j] > next)
                    {
                        board[i - 1, j] = next;
                        result[next].Add(new Index(i - 1, j));
                    }
                    if (i < H - 1 && board[i + 1, j] > next)
                    {
                        board[i + 1, j] = next;
                        result[next].Add(new Index(i + 1, j));
                    }
                    if (j > 0 && board[i, j - 1] > next)
                    {
                        board[i, j - 1] = next;
                        result[next].Add(new Index(i, j - 1));
                    }
                    if (j < W - 1 && board[i, j + 1] > next)
                    {
                        board[i, j + 1] = next;
                        result[next].Add(new Index(i, j + 1));
                    }
                }
                if (result[next].Count == 0) return count;
            }
        }

        const int mod = 1000000007;
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
    }

    public class ConsoleReader
    {
        public virtual string String() => Console.ReadLine();
        public int Int32() => int.Parse(String());
        public long Int64() => long.Parse(String());
        public ulong UInt64() => ulong.Parse(String());
        public double Double() => double.Parse(String());
        public string[] Split() => String().Split().ToArray();
        public int[] SplitInt32() => String().Split().Select(s => int.Parse(s)).ToArray();
        public long[] SplitInt64() => String().Split().Select(s => long.Parse(s)).ToArray();
        public ulong[] SplitUInt64() => String().Split().Select(s => ulong.Parse(s)).ToArray();
        public double[] SplitDouble() => String().Split().Select(s => double.Parse(s)).ToArray();

        public IEnumerable<string> Repeat(int count)
        {
            for (int i = 0; i < count; i++)
                yield return String();
        }
        public IEnumerable<int> RepeatInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Int32();
        }
        public IEnumerable<long> RepeatInt64(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Int64();
        }
        public IEnumerable<string[]> RepeatSplit(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Split();
        }
        public IEnumerable<int[]> RepeatSplitInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return SplitInt32();
        }
    }
    static class DicExt
    {
        public static V GetOrDefault<K, V>(this Dictionary<K, V> dic, K key, V defaultValue = default(V))
        {
            V val;
            return dic.TryGetValue(key, out val) ? val : defaultValue;
        }
    }
}


Measured memory_bytes: 34516