function getCell(w, h, input, W, H) {
    return input[Math.max(0, Math.min(h, H-1))][Math.max(0, Math.min(W-1, w))];
}

function insert(w, h, input, W, H, value) {
    input[Math.max(0, Math.min(h, H-1))][Math.max(0, Math.min(W-1, w))] = value;
}

function Main(input) {
    const H = parseInt(input.shift());
    const W = parseInt(input.shift());

    isBlack = false;
    var count = -1;

    var currentMap = [];
    input.forEach(element => {
        currentMap.push(element.split(""));
    });

    while (!isBlack) {
        var isDirty = false;
        var nextMap = [];
        currentMap.forEach(element => {
            nextMap.push([].concat(element))
        });
        
        for (var h = 0; h < H; h++) {
            for (var w = 0; w < W; w++) {
                var cell = getCell(w, h, currentMap, W, H);
                if (cell == "#") {
                    insert(w - 1, h - 1, nextMap, W, H, "#");
                    insert(w - 1, h + 1, nextMap, W, H, "#");
                    insert(w + 1, h - 1, nextMap, W, H, "#");
                    insert(w + 1, h + 1, nextMap, W, H, "#");
                } else {
                    isDirty = true;
                }
            }
        }
        count++;
        isBlack = !isDirty;
        currentMap = nextMap;
    }

    console.log(count);
}

// 1行入力の場合
// Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

// 改行で分割
// Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n/));

// 改行・空白で分割
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));