
function Main(lines) {
    lines = lines.split("\n");
    
    var H = Number(lines[0].split(" ")[0]);
    var W = Number(lines[0].split(" ")[1]);

    lines.shift();

    var q = []

    for (var i = 0; i < H; i++) {
        for (var j = 0; j < W; j++) {
            if (lines[i][j] === "#") { q.push([i, j, 0]); }
        }
    }

    var max = 0; var count = 0;
    var m = Array(H).fill(-1).map(i => i = Array(W).fill(-1));

    while (q.length) {
        var a = q.shift();
        var y = a[0], x = a[1];
        count = a[2];

        if (m[y][x] !== -1) { continue; }

        m[y][x] = count;
        max = Math.max(max, count);

        if (y + 1 < H) { q.push([y + 1, x, count + 1]); }
        if (0 <= y - 1) { q.push([y - 1, x, count + 1]); }
        if (x + 1 < W) { q.push([y, x + 1, count + 1]); }
        if (0 <= x - 1) { q.push([y, x - 1, count + 1]); }
    }
    console.log(max);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));





