'use strict';

const readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin
});
var lineNo = 0;
rl.on('line', (line) => {
    onEachLine(line.trim(), lineNo++);
});
rl.on('close', onInputClosed);
function debug(){
    if( DEBUG ){
        console.log.apply(null, arguments);
    }
}

var DEBUG = 0;

var matrix = [];
var black = [];
var white;
var H;
var W;

function onEachLine(line, lineNo) {
    if( lineNo === 0 ){
        var d = line.split(/\s+/);
        H = parseInt(d[0]);
        W = parseInt(d[0]);
        white = H*W;
        matrix.push(Array(W+2).fill('#'));
        return;
    }
    var row = lineNo;
    line = '#'+line+'#';
    matrix[row] = line.split('');
    for (var i=1,len=matrix[row].length; i<len-1; i++) {
        if (matrix[row][i] === '#') {
            white -= 1;
            black.push([row, i]);
        }
    }
    matrix.push(Array(W+2).fill('#'));
}


function onInputClosed(){
    var neighbour = [[-1, 0],[1,0],[0,-1],[0,1]];
    var nLen = neighbour.length;
    var count = 0;
    black.push([-1,-1]);
    debug(white);
    debug(black);
    debug(matrix);
    while(white>0){
        var b = black.shift();
        if( b[0] === -1 ){
            debug(white);
            debug(black);
            debug(matrix);
            count += 1;
            black.push([-1, -1]);
            continue;
        }
        for(var j=0; j<nLen; j++) {
            var r = b[0] + neighbour[j][0];
            var c = b[1] + neighbour[j][1];
            if(matrix[r][c] === '.' ){
                matrix[r][c] = '#';
                white -= 1;
                if (white <= 0){
                    count += 1;
            debug(white);
            debug(black);
            debug(matrix);
                    break;
                }
                black.push([r,c]);
            }
        }
    }
    console.log(count);
}




