using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoderSolve.Tool;

namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;

        
        
        //static char[] s;
        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            var input = cin.SplitReader();
            int H = input[0];
            int W = input[1];

            bool[,] nero = new bool[H + 2, W + 2];
            var Q = new Queue<Pair<int>>();

            int b = 0;

            for (var i = 0; i <= H + 1; i++) 
            {
                if (i == 0 || i == H + 1)
                {
                    for(var j = 0; j <= W + 1; j++)
                    {
                        nero[i, j] = true;
                    }
                    continue;
                }
                string A = Console.ReadLine();
                for (var j = 0; j <= W + 1; j++) 
                {
                    if (j == 0 || j == W + 1)
                    {
                        nero[i, j] = true;
                        continue;
                    }

                    if (A[j - 1] == '#')
                    {
                        nero[i, j] = true;
                        b++;
                        Q.Enqueue(new Pair<int>(i, j));
                    }
                    else
                    {
                        nero[i, j] = false;
                    }
                }
            }

            long ans = 0;
            while (Q.Count() > 0)
            {
                int c = 0;
                for(var a = 0; a < b; a++)
                {
                    var p = Q.Dequeue();
                    int i = p.variable;
                    int j = p.index;
                    if (!nero[i - 1, j])
                    {
                        nero[i - 1, j] = true;
                        Q.Enqueue(new Pair<int>(i - 1, j));
                        c++;
                    }
                    if (!nero[i + 1, j])
                    {
                        nero[i + 1, j] = true;
                        Q.Enqueue(new Pair<int>(i + 1, j));
                        c++;
                    }
                    if (!nero[i, j - 1])
                    {
                        nero[i, j - 1] = true;
                        Q.Enqueue(new Pair<int>(i, j - 1));
                        c++;
                    }
                    if (!nero[i, j + 1])
                    {
                        nero[i, j + 1] = true;
                        Q.Enqueue(new Pair<int>(i, j + 1));
                        c++;
                    }
                }
                if (c > 0)
                {
                    ans++;
                    b = c;
                }
            }

            Console.WriteLine(ans);

            //Console.Out.Flush();
        }

        

    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for(var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
    }

    struct Pair<T> : IComparable<Pair<T>> where T : IComparable<T>
    {
        public T variable;
        public int index;

        public Pair(T val, int i)
        {
            variable = val;
            index = i;
        }

        public int CompareTo(Pair<T> otherPair)
        {
            return variable.CompareTo(otherPair.variable);
        }

        public int CompareIndex(Pair<T> otherPair)
        {
            return index.CompareTo(otherPair.index);
        }
    }



}






Measured memory_bytes: 30560