//
// AGC033A
// URL : https://atcoder.jp/contests/agc033/tasks/agc033_a
// 
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Runtime.Serialization;
using System.Xml;

namespace AtCoder
{
    class AGC033A
    {
        public static readonly long MOD_CONST = 1000000007;//(long)Math.Pow(10, 9) + 7;


        static void Main(string[] args)
        {
            //出力高速化
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }
        public static readonly char BLACK = '#';
        public static readonly char WHITE = '.';
        public static readonly int[] dx = new int[4] { 1, -1, 0, 0 };
        public static readonly int[] dy = new int[4] { 0, 0, 1, -1 };
        public class Masu : IEquatable<Masu>
        {
            public int h;
            public int w;
            public Masu(int _h, int _w) { h = _h; w = _w; }
            public bool Equals(Masu Other)
            {
                return h == Other.h && w == Other.w;
            }
        }

        public static void Solve()
        {
            var inputArray = Console.ReadLine().Split(' ').Select(_inputStr => int.Parse(_inputStr)).ToArray();
            int H = inputArray[0];//縦幅
            int W = inputArray[1];//横幅
            var Maze = new char[H, W];//迷路
            var blackMasuList = new Queue<Masu>(H * W);
            var checkTile = new bool[H, W];

            for (int h = 0; h < H; ++h)
            {
                var s = Console.ReadLine();
                for (int w = 0; w < W; ++w)
                {
                    char c = s[w];
                    Maze[h, w] = c;
                    if (c == BLACK) {
                        blackMasuList.Enqueue(new Masu(h, w));
                        checkTile[h, w] = true;
                    }
                }
            }
            int ans = 0;
            var nextBlackMasuList = new Queue<Masu>(H * W);
            while (blackMasuList.Count != 0)
            {
                //search phase
                //黒マスの周囲の白マスは黒くなる
                foreach (var blackMasu in blackMasuList)
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        int nh = blackMasu.h + dy[i];
                        int nw = blackMasu.w + dx[i];
                        if (nh < 0 || H <= nh) { continue; }
                        if (nw < 0 || W <= nw) { continue; }
                        if (Maze[nh, nw] == BLACK) { continue; }
                        if (checkTile[nh,nw] == true) { continue; }
                        checkTile[nh, nw] = true;

                        nextBlackMasuList.Enqueue(new Masu(nh, nw));
                    }
                }
                //paint phase
                blackMasuList = new Queue<Masu>(nextBlackMasuList);
                if (nextBlackMasuList.Count > 0)
                {
                    ans++;
                }
                nextBlackMasuList.Clear();
                //debugPrint(Maze, H, W);
            }
            Console.WriteLine(ans);
        }
        public static void debugPrint(char[,] Maze, int H, int W)
        {
            Console.WriteLine();
            for (int h = 0; h < H; ++h)
            {
                for (int w = 0; w < W; ++w)
                {
                    Console.Write( Maze[h,w] );
                }
                Console.WriteLine();
            }
        }

        public static void _Solve()
        {
            var inputArray = Console.ReadLine().Split(' ').Select(_inputStr => int.Parse(_inputStr)).ToArray();
            int H = inputArray[0];//縦幅
            int W = inputArray[1];//横幅
            var Maze = new char[H, W];//迷路

            for (int h = 0; h < H; ++h)
            {
                var s = Console.ReadLine();
                for (int w = 0; w < W; ++w)
                {
                    char c = s[w];
                    Maze[h, w] = c;
                }
            }
            var blackMasuList = new List<Masu>(1000);
            int ans = 0;
            bool isEnd = false;
            //BFS
            while (isEnd == false)
            {
                isEnd = true;
                for(int h = 0; h < H; ++h)
                {
                    for(int w = 0; w < W; ++w)
                    {
                        if(Maze[h,w] == BLACK) { continue; }
                        //白マスが見つかった
                        isEnd = false;
                        for (int i = 0; i < 4; ++i)
                        {
                            int nh = h + dy[i];
                            int nw = w + dx[i];
                            if (nh < 0 || H <= nh) { continue; }
                            if (nw < 0 || W <= nw) { continue; }
                            if (Maze[nh, nw] == BLACK)
                            {
                                blackMasuList.Add(new Masu(h, w));
                                break;
                            }
                        }
                    }
                }
                if (blackMasuList.Count > 0)
                {
                    foreach(var m in blackMasuList)
                    {
                        Maze[m.h, m.w] = BLACK;
                    }
                    ++ans;
                    blackMasuList.Clear();
                }
            }

            Console.WriteLine(ans);
        }


        //---------------------------------------------------------------------------------
#region MyLib

        /// <summary>
        /// グラフ系
        /// </summary>
        public class Node
        {
            public Node(long val){
                this.Value = val;
                this.Children = new List<Node>();
            }

            public Node(long val, List<Node> children)
            {
                this.Value = val;
                this.Children = children;
            }

            public long Value { get; set; }
            public List<Node> Children { get; set; }
        }

        /// <summary>
        /// Clamping
        /// </summary>
        /// <typeparam name="T">比較型</typeparam>
        /// <param name="x">clampしたい値</param>
        /// <param name="min">最小値</param>
        /// <param name="max">最大値</param>
        /// <returns>clamp済みの値</returns>
        public static T Clamp<T>(T x, T min, T max) where T : IComparable<T>
        {
            if (x.CompareTo(min) < 0) { return min; }
            else if (x.CompareTo(max) > 0) { return max; }
            else return x;
            //return Math.Max(Math.Min(x, max), min);
        }

        /// <summary>
        /// 指定された底log_baseでの, 対数を計算
        /// </summary>
        /// <param name="x"></param>
        /// <param name="log_base">指定の底</param>
        /// <returns></returns>
        public static double LogBase(double x, double log_base)
        {
            //log_b(N) = log_a(N) / log_a(B)より
            return Math.Log(x) / Math.Log(log_base);
        }

        /// <summary>
        /// 初項a, 公差d, 項数nの数列の和
        /// </summary>
        /// <param name="n">求めたいところ</param>
        /// <returns>初項からxまで足した値</returns>
        static long SumSeries(long a, long d, long n)
        {
            return (2 * a + (n - 1) * d) * n / 2;
        }
        /// <summary>
        /// 累積和の配列を計算する
        /// Sum[ a[0], a[i] )がs[i+1]に入っている
        /// s[0]  : 0                //一切和を取らない場合
        /// s[1]  : ls[0]            //a[0]   + s[0] = a[0]
        /// s[2]  : ls[1] + s[1]     //a[1]   + a[0]
        /// ...
        /// s[N]  : ls[N-1] + s[N-1] //a[N-1] + ... + a[0]
        /// s[N+1]: ls[N] + s[N]     //a[N]   + ... + a[0]
        /// 
        /// 例: [1, 7)の和(a[1] + ... + a[6])
        /// s[1] = a[0] //[0, 1)
        /// s[7] = a[0] + a[1] + ... + a[6] //[0, 7)
        /// よってs[7] - s[1]);
        /// </summary>
        /// <param name="ls">計算したい配列</param>
        /// <returns>累積和配列</returns>
        static List<long> AggregateSumList(List<long> a)
        {
            var s = new List<long>(a.Count + 1);
            if (a.Count == 0)
            {
                return s;
            }
            s.Add(0);//s[0] = 0
            for (int i = 0; i < a.Count; ++i)
            {
                s.Add(a[i] + s[i]);
            }
            return s;
        }


        /// <summary>
        /// 与えられた数が素数かどうかを計算する
        /// </summary>
        /// <param name="num">対象数</param>
        /// <returns>true:素数, false:素数ではない(合成数)</returns>
        public static bool isPrime(int num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false;

            double sqrtNum = Math.Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    return false;
                }
            }
            return true;
        }

        /// <summary>
        /// 順列mPnを計算する
        /// </summary>
        /// <param name="m"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static long Permutation(long m, long n)
        {
            long ret = 1;
            for (var i = 0; i < n; ++i)
            {
                ret *= m - i;
            }
            return ret;
        }
        /// <summary>
        /// 組み合わせmCnを計算する
        /// </summary>
        /// <param name="m"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static long Combination(long m, long n)
        {
            if (m == n || n == 0)
            {
                return 1;
            }
            long ans = 1;
            for (var i = 1; i <= n; ++i)
            {
                ans = ans * (m - i + 1) / i;
            }
            return ans;
        }

        static long Gcd(long m, long n)
        {
            if (n == 0) return m;
            return Gcd(n, m % n);
        }

        static long Lcm(long m, long n)
        {
            var gcd = Gcd(m, n);
            //return (m * n) / gcd;
            return m / gcd * n;//桁あふれ対策
        }
#endregion MyLib
    }
}



Measured memory_bytes: 60788