

function Main(input) {
  input = input.split("\n");
  var H = parseInt(input[0].split(" ")[0]);
  var W = parseInt(input[0].split(" ")[1]);
  var A = new Array(H);
  var A = new Array(H+2);
  var C = new Array();
  var C1=new Array(W+2).fill(-1);
  A[0]=C1;
  for(var i=0;i<H;i++){
    var tmp=input[i+1].split("");
    for(var j=0;j<W;j++){
      if(tmp[j]=="#"){
        C.push([i+1,j+1]);
        tmp[j]=0;
      }
    }
    tmp.splice(0,0,-1);
    tmp.push(-1);
    A[i+1]=tmp;
  }
  A[H+1]=C1;
  var flag=0;
  var ans =0;
  while(C.length!=0){
    if(A[C[0][0]+1][C[0][1]]=="."){
      A[C[0][0]+1][C[0][1]]=A[C[0][0]][C[0][1]]+1;
      C.push([C[0][0]+1,C[0][1]]);
      ans=Math.max(ans,A[C[0][0]][C[0][1]]+1);
    }
    if(A[C[0][0]-1][C[0][1]]=="."){
      A[C[0][0]-1][C[0][1]]=A[C[0][0]][C[0][1]]+1;
      C.push([C[0][0]-1,C[0][1]]);
      ans=Math.max(ans,A[C[0][0]][C[0][1]]+1);
    }
    if(A[C[0][0]][C[0][1]+1]=="."){
      A[C[0][0]][C[0][1]+1]=A[C[0][0]][C[0][1]]+1;
      C.push([C[0][0],C[0][1]+1]);
      ans=Math.max(ans,A[C[0][0]][C[0][1]]+1);
    }
    if(A[C[0][0]][C[0][1]-1]=="."){
      A[C[0][0]][C[0][1]-1]=A[C[0][0]][C[0][1]]+1;
      C.push([C[0][0],C[0][1]-1]);
      ans=Math.max(ans,A[C[0][0]][C[0][1]]+1);
    }
    C.shift();
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));