void main()
{
    long[] tmp = rdRow;
    long h = tmp[0], w = tmp[1];

    string[] a = new string[h];
    coord[] que;
    long[][] dist = new long[][](h, w);
    foreach (i; 0 .. h)
    {
        dist[i][] = -1;
    }
    foreach (i; 0 .. h)
    {
        a[i] = rdStr;
        foreach (j, c; a[i])
        {
            if (c == '#')
            {
                que ~= coord(i, j);
                dist[i][j] = 0;
            }
        }
    }

    long[] dy = [-1, 0, 1, 0], dx = [0, 1, 0, -1];
    long result;
    while (!que.empty)
    {
        long y = que[0].y, x = que[0].x;
        que.popFront;
        foreach (i; 0 .. 4)
        {
            long y1 = y + dy[i], x1 = x + dx[i];
            if (y1 < 0 || h <= y1 || x1 < 0 || w <= x1) continue;
            if (dist[y1][x1] >= 0) continue;

            dist[y1][x1] = dist[y][x] + 1;
            result = max(result, dist[y1][x1]);
            que ~= coord(y1, x1);
        }
    }

    result.writeln;
}

alias Tuple!(long, "y", long, "x") coord;

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;