using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static int H;
        static int W;
        static string[] S;
        static int[,] used;
        static Queue<Tuple<int, int>> que;
        //static long mod = 1000000007;
        //static char[] az = Enumerable.Range('a', 'z' - 'a' + 1).Select(i => (Char)i).ToArray();
        static void Main(string[] args)
        {
            //var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            //var N = long.Parse(Console.ReadLine());
            var HW = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            H = HW[0];
            W = HW[1];
            used = new int[H, W];
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    used[i, j] = - 1;
                }
            }

            S = new string[H];
            for (int i = 0; i < H; i++)
            {
                S[i] = Console.ReadLine();
            }
            que = new Queue<Tuple<int, int>>();

            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if(S[i][j] == '#')
                    {
                        used[i, j] = 0;
                        if(i > 0 && used[i - 1, j] == -1 && S[i-1][j] == '.')
                        {
                            que.Enqueue(new Tuple<int, int>(i - 1, j));
                            used[i - 1, j] = used[i, j] + 1;
                        }

                        if (j > 0 && used[i, j - 1] == -1 && S[i][j - 1] == '.')
                        {
                            que.Enqueue(new Tuple<int, int>(i, j - 1));
                            used[i, j - 1] = used[i, j] + 1;
                        }

                        if (i < H - 1 && used[i + 1, j] == -1 && S[i + 1][j] == '.' )
                        {
                            que.Enqueue(new Tuple<int, int>(i + 1, j));
                            used[i + 1, j] = used[i, j] + 1;
                        }

                        if (j < W - 1 && used[i, j + 1] == -1 && S[i][j + 1] == '.'
                            )
                        {
                            que.Enqueue(new Tuple<int, int>(i, j + 1));
                            used[i, j + 1] = used[i, j] + 1;
                        }
                    }
                }
            }

            Console.WriteLine(WFS());
        }

        static int WFS()
        {
            int count = 0;
            if (que.Count() > 0) count++;
                
            while(que.Count() > 0)
            {
                var top = que.Dequeue();
                var i = top.Item1;
                var j = top.Item2;
                
                    if (i > 0 && used[i - 1, j] == -1)
                    {
                        que.Enqueue(new Tuple<int, int>(i - 1, j));
                        used[i - 1, j] = used[i, j] + 1;
                        count = Max(count, used[i, j] + 1);
                    }

                    if (j > 0 && used[i, j - 1] == -1)
                    {
                        que.Enqueue(new Tuple<int, int>(i, j - 1));
                        used[i, j - 1] = used[i, j] + 1;
                        count = Max(count, used[i, j] + 1);
                    }

                    if (i < H - 1 && used[i + 1, j] == -1)
                    {
                        que.Enqueue(new Tuple<int, int>(i + 1, j));
                        used[i + 1, j] = used[i, j] + 1;
                        count = Max(count, used[i, j] + 1);
                    }

                    if (j < W - 1 && used[i, j + 1] == -1)
                    {
                        que.Enqueue(new Tuple<int, int>(i, j + 1));
                        used[i, j + 1] = used[i, j] + 1;
                        count = Max(count, used[i, j] + 1);
                    }
                
            }
            return count;
        }
    }
}


Measured memory_bytes: 63744