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

namespace CSharp
{
    static class Program
    {
        struct Point
        {
            public int X { get; }
            public int Y { get; }

            public Point(int x, int y)
            {
                X = x;
                Y = y;
            }
        }

        static readonly int[] dx = { 0, 0, 1, -1 };
        static readonly int[] dy = { 1, -1, 0, 0 };
        static int h, w;

        static bool IsInRange(int x, int y)
            => (uint)x < (uint)h && (uint)y < (uint)w;

        static void Main(string[] args)
        {
            ReadInt(out h, out w);
            char[][] A = Enumerable.Repeat(0, h).Select(_ => Console.ReadLine().ToArray()).ToArray();
            Queue<Point> points = new Queue<Point>();

            for (int x = 0; x < A.Length; x++)
            {
                for (int y = 0; y < A[x].Length; y++)
                {
                    if (A[x][y] == '#')
                    {
                        points.Enqueue(new Point(x, y));
                    }
                }
            }

            int ans = 0;

            while (points.Count > 0)
            {
                Queue<Point> next = new Queue<Point>();
                bool occured = false;

                while (points.Count > 0)
                {
                    Point p = points.Dequeue();
                    for (int i = 0; i < dx.Length; i++)
                    {
                        int x = p.X + dx[i], y = p.Y + dy[i];
                        if (IsInRange(x, y) && A[x][y] == '.')
                        {
                            A[x][y] = '#';
                            next.Enqueue(new Point(x, y));
                            occured = true;
                        }
                    }
                }

                if (occured)
                {
                    ans++;
                }

                points = next;
            }

            Console.WriteLine(ans);
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

Measured memory_bytes: 38740