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

public struct Point
{
    public int X;
    public int Y;

    public Point(Point p)
    {
        X = p.X;
        Y = p.Y;
    }

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

    public static bool operator ==(Point a, Point b)
    {
        return (a.X == b.X && a.Y == b.Y);
    }

    public static bool operator !=(Point a, Point b)
    {
        return !(a == b);
    }

    //objと自分自身が等価のときはtrueを返す
    public override bool Equals(object obj)
    {
        if (!(obj is Point))
        {
            return false;
        }

        Point p = (Point)obj;
        return (X == p.X && Y == p.Y);
    }

    //Equalsがtrueを返すときに同じ値を返す
    public override int GetHashCode()
    {
        return (X << 16) ^ Y;
    }

    public Point Clone()
    {
        return new Point(X, Y);
    }

    public void Reverse()
    {
        X = -X;
        Y = -Y;
    }

    public static Point operator +(Point a, Point b)
    {
        return new Point(a.X + b.X, a.Y + b.Y);
    }

    public static Point operator -(Point a, Point b)
    {
        return new Point(a.X - b.X, a.Y - b.Y);
    }

    public static Point operator *(Point a, int i)
    {
        return new Point(a.X * i, a.Y * i);
    }

    public static Point operator /(Point a, int i)
    {
        return new Point(a.X / i, a.Y / i);
    }
    public static Point operator +(Point a)
    {
        return new Point(+a.X, +a.Y);
    }

    public static Point operator -(Point a)
    {
        return new Point(-a.X, -a.Y);
    }

    public override string ToString()
    {
        return string.Format("({0},{1})", X, Y);
    }

    private IEnumerable<Point> _GetNeighbors()
    {
        yield return new Point(X + 1, Y + 0);
        yield return new Point(X + 0, Y + 1);
        yield return new Point(X - 1, Y + 0);
        yield return new Point(X + 0, Y - 1);
    }

    public bool InRange(Point max)
    {
        return 0 <= X && X < max.X && 0 <= Y && Y < max.Y;
    }

    public IEnumerable<Point> GetNeighbors()
    {
        return _GetNeighbors().Where(p => p.InRange(Max));
    }

    public static Point Max;
}

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var h = vals[0];
        var w = vals[1];
        Point.Max = new Point(w, h);
        var grid = new char[h][];
        for (int i = 0; i < h; i++)
        {
            grid[i] = Console.ReadLine().ToCharArray();
        }

        int count = 0;
        var current = new List<Point>();
        for (int y = 0; y < h; y++)
        {
            for (int x = 0; x < w; x++)
            {
                if (grid[y][x] == '#')
                {
                    current.Add(new Point(x, y));
                }
            }
        }

        while (true)
        {
            var next = current.SelectMany(cur => cur.GetNeighbors().Where(nei => grid[nei.Y][nei.X] == '.')).Distinct().ToList();
            foreach (var p in next)
            {
                grid[p.Y][p.X] = '#';
            }

            if (next.Count == 0)
            {
                break;
            }
            current = next;
            count++;
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 47348