var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var H = Number(lines[0].split(" ")[0]);
    var W = Number(lines[0].split(" ")[1]);

    lines.shift();

    var q = []
    var l = Array(H).fill(0).map(i => i = Array(W).fill(0))

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


    var max = 0; var ans = 0;

    while (q.length) {
        ans++;
        var qq = q.concat();

        for (var i = 0; i < q.length; i++) {
            var a = qq.shift();
            var y = a[0], x = a[1];

            if (0 <= y + 1 && y + 1 < H) { if (l[y + 1][x] === ".") { l[y + 1][x] = "#"; qq.push([y + 1, x]); } }
            if (0 <= y - 1 && y - 1 < H) { if (l[y - 1][x] === ".") { l[y - 1][x] = "#"; qq.push([y - 1, x]); } }
            if (0 <= x + 1 && x + 1 < W) { if (l[y][x + 1] === ".") { l[y][x + 1] = "#"; qq.push([y, x + 1]); } }
            if (0 <= x - 1 && x - 1 < W) { if (l[y][x - 1] === ".") { l[y][x - 1] = "#"; qq.push([y, x - 1]); } }
        
        }

        q = qq.concat();
    }
    console.log(ans-1);
});
