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

class Program
{
    static int H, W;
    static string[] INS;

    public static void Main(string[] args)
    {
        H = Input.NextInt();
        W = Input.NextInt();
        INS = new string[H];
        for (int i = 0; i < H; i++)
            INS[i] = Input.NextString();

        var ban = new bool[H][];
        for (int i = 0; i < H; i++)
        {
            ban[i] = new bool[W];
        }

        for (int i = 0; i < INS.Length; i++)
        {
            var l = INS[i];
            for (int j = 0; j < l.Length; j++)
            {
                var a = l[j] == '#';
                if (a)
                    ban[i][j] = true;
            }
        }

        var awa = new HashSet<Tuple<int, int>>();
        for (int i = 0; i < INS.Length; i++)
        {
            var l = INS[i];
            for (int j = 0; j < l.Length; j++)
            {
                if (ban[i][j])
                {
                    if (((i - 1) >= 0 && !ban[i - 1][j])
                     || ((i + 1) < H && !ban[i + 1][j])
                     || ((j - 1) >= 0 && !ban[i][j - 1])
                     || ((j + 1) < W && !ban[i][j + 1]))
                    {
                        awa.Add(new Tuple<int, int>(i, j));
                    }
                }
            }
        }

        if (awa.Count == 0)
        {
            Console.WriteLine(0);
            return;
        }

        int count = -1;
        while (true)
        {
            if (awa.Count == 0)
            {
                Console.WriteLine(count);
                return;
            }
            //if (awa.Count > 3000)
            //{
            //    Console.WriteLine(3000);
            //    return;
            //}
            var wa = new HashSet<Tuple<int, int>>();
            foreach (var bla in awa)
            {
                var i = bla.Item1;
                var j = bla.Item2;
                if ((i - 1) >= 0)
                {
                    if (!ban[i - 1][j])
                    {
                        ban[i - 1][j] = true;
                        wa.Add(new Tuple<int, int>(i - 1, j));
                    }
                }
                if ((i + 1) < H)
                {
                    if (!ban[i + 1][j])
                    {
                        ban[i + 1][j] = true;
                        wa.Add(new Tuple<int, int>(i + 1, j));
                    }
                }
                if ((j - 1) >= 0)
                {
                    if (!ban[i][j - 1])
                    {
                        ban[i][j - 1] = true;
                        wa.Add(new Tuple<int, int>(i, j - 1));
                    }
                }
                if ((j + 1) < W)
                {
                    if (!ban[i][j + 1])
                    {
                        ban[i][j + 1] = true;
                        wa.Add(new Tuple<int, int>(i, j + 1));
                    }
                }
            }
            awa = wa;
            count++;

        }
    }
}

public static class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 79748