'use strict'
function Main(input){
  input=input.trim().split(/\n/);
  var firstline=input.shift();
  firstline=firstline.split(/\s+/).map(x=>x-0);
  var H=firstline[0];
  var W=firstline[1];
  var matrix=input.map(str=>str.split('').map(x=>x==='#'?0:1));
  var Black=[[]];
  matrix.forEach(function(row,i){
    row.forEach(function(x,j){
      if(x===0)Black[0].push([i,j]);
    });
  });
  if(!(Black[0].length<H*W)){
    console.log(0);
    return;
  }
  var generation=1;
  while(true){
    Black[generation]=[];
    let B=Black[generation-1];
    let C=Black[generation];
    B.forEach(function(ij){
      let i=ij[0];
      let j=ij[1];
      if(matrix[i-1]&&matrix[i-1][j]){
        matrix[i-1][j]=0;
        C.push([i-1,j]);
      }
      if(matrix[i+1]&&matrix[i+1][j]){
        matrix[i+1][j]=0;
        C.push([i+1,j]);
      }
      if(matrix[i][j-1]){
        matrix[i][j-1]=0;
        C.push([i,j-1]);
      }
      if(matrix[i][j+1]){
        matrix[i][j+1]=0;
        C.push([i,j+1]);
      }
    });
    if(C.length===0)break;
    generation++;
  }
  console.log(generation-1);
}

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