var heredoc = null;
if (process.argv[2] == "-debug") {
    debug = true;
    heredoc = (()=>{/*
3 3
...
.#.
...
*/}).toString().replace(/^[^\/]+\/\*\n/, "").replace(/\*\/}$/m, "");
}

function main(input) {
    var wrk = input.shift().split(" ");
    H = parseInt(wrk.shift(), 10);
    W = parseInt(wrk.shift(), 10);
    mat = [];
    var lines = Array(H);
    for(var i = 0; i<H;i++)
    {
        line = input.shift().split("");
        for(var j = 0; j<W; j++)
        {
            if(line[j]=="#")
            {
                line[j] = 1;
                mat.push([i, j, 0]);
            }
            else
            {
                line[j] = 0;
            }
        }
        lines[i] = line;
    }

    p = function(i,j,cnt){
        if(lines[i][j]==0)
        {
            lines[i][j] = 1;
            mat.push([i, j, cnt+1]);
        }
    };
    while(mat.length > 0)
    {
        var wrk = mat.shift();
        var i = wrk.shift();
        var j = wrk.shift();
        var cnt = wrk.shift();

        if(i > 0)
            p(i-1,j, cnt);
        if(i < H-1)
            p(i+1,j, cnt);
        if(j > 0)
            p(i,j-1, cnt);
        if(j < W-1)
            p(i,j+1, cnt);
    }
    console.log(cnt);

}

var lines;
if (!heredoc)
    lines = require("fs").readFileSync("/dev/stdin", "utf8");
else
    lines = heredoc;
main(lines.trim().split("\n"));
