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, 0]); }
        }
    }


    var max = 0; var count = 0;

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

        max = Math.max(max, count);

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

    }
    console.log(max);
});
