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

namespace AGC033ATeacher2
{
    class Program
    {
            struct pos
        {
            public int x;
            public int y;
        }
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int H = int.Parse(str[0]);
            int W = int.Parse(str[1]);
            int[,] A = new int[H, W];
            int max_DP = H + W - 1;
            var list = new List<pos>();
            pos p = new pos();
            for (var i = 0; i < H; i++)
            {
                string str2 = Console.ReadLine();
                for (var j = 0; j < W; j++)
                {
                    if (str2.Substring(j, 1) == "#")
                    {
                        A[i, j] = 0;
                        p.x = i;
                        p.y = j;
                        list.Add(p);
                    }
                    else
                    {
                        A[i, j] = max_DP;
                    }
                }
            }
            int max = 0;
            while (list.Count > 0)
            {
                var list2 = new List<pos>(list);
                list.Clear();
                for (var i = 0; i < list2.Count; i++)
                {
                    int x = list2[i].x;
                    int y = list2[i].y;
                    if (x > 0)
                    {
                        if (A[x - 1, y] == max_DP)
                        {
                            A[x - 1, y] = A[x, y] + 1;
                            max = Math.Max(max, A[x-1, y]);
                            p.x = x - 1;
                            p.y = y;
                            list.Add(p);
                        }
                    }
                    if (x < H - 1)
                    {
                        if (A[x + 1, y] == max_DP)
                        {
                            A[x + 1, y] = A[x, y] + 1;
                            max = Math.Max(max, A[x+1, y]);
                            p.x = x + 1;
                            p.y = y;
                            list.Add(p);
                        }
                    }
                    if (y > 0)
                    {
                        if (A[x, y - 1] == max_DP)
                        {
                            A[x, y - 1] = A[x, y] + 1;
                            max = Math.Max(max, A[x, y-1]);
                            p.x = x;
                            p.y = y - 1;
                            list.Add(p);
                        }
                    }
                    if (y < W - 1)
                    {
                        if (A[x, y + 1] == max_DP)
                        {
                            A[x, y + 1] = A[x, y] + 1;
                            max = Math.Max(max, A[x, y+1]);
                            p.x = x;
                            p.y = y + 1;
                            list.Add(p);
                        }
                    }
                }
            }
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 32660