import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    long H, W;
    scan(H, W);
    long[2][] black;
    auto A = new bool[][](H, W);
    foreach (i; 0 .. H)
    {
        auto s = sread();
        foreach (j, c; s)
            if (c == '#')
            {
                black ~= [i, j];
                A[i][j] = true;
            }
    }

    long cnt;
    while (true)
    {
        long[2][] tmp;
        foreach (b; black)
        {
            long y = b[0];
            long x = b[1];
            if (0 < y && !A[y - 1][x])
            {
                A[y - 1][x] = true;
                tmp ~= [y - 1, x];
            }
            if (0 < x && !A[y][x - 1])
            {
                A[y][x - 1] = true;
                tmp ~= [y, x - 1];
            }
            if (y + 1 < H && !A[y + 1][x])
            {
                A[y + 1][x] = true;
                tmp ~= [y + 1, x];
            }
            if (x + 1 < H && !A[y][x + 1])
            {
                A[y][x + 1] = true;
                tmp ~= [y, x + 1];
            }
        }
        if (tmp.empty)
        {
            writeln(cnt);
            return;
        }
        else
        {
            cnt++;
            black = tmp;
        }
    }
}
