
function returnNextStr(input, index, L) {
  let result = index;
  if(index-1 > -1){
    result[index-1] = '#';
  }
  if(index+1 < L){
    result[index+1] = '#';
  }
  if(index-W > -1){
    result[index-W] = '#';
  }
  if(index+W < L){
    result[index+W] = '#';
  }
  
  return result;
}

function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  
  let result = 0;
  
  let tmp = input[0].split(" ");
  let H = parseInt(tmp[0], 10);
  let W = parseInt(tmp[1], 10);
  let L = H*W;
  let resltStr = '';
  for (let i=0; i < H; i++) {
    resltStr += input[i+1];
  }
  let tmpStr = resltStr;
  
  while(resltStr.indexOf('.') != -1){
    for(let i = 0; i < L; i++) 
      if(resltStr[i] == '#'){
        tmpStr = returnNextStr(tmpStr, i, L);
      }
    }
    resltStr = tmpStr;
    result++;
  }
  
  //出力
  console.log(result);
}
