function returnNextStr(input, index, L, W) {
  let result = input.slice();
  if (index - 1 > -1) {
    result[index - 1] = '#';
  }
  console.log(result);
  if (index + 1 < L) {
    result[index + 1] = '#';
  }
  console.log(result);
  if (index - W > -1) {
    result[index - W] = '#';
  }
  console.log(result);
  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 resltArr = resltStr.split('');
  let tmpArr = resltArr.slice();
  while (resltArr.indexOf('.') != -1 && resltArr.indexOf('#') != -1) {
    for (let i = 0; i < L; i++) {
      if (resltArr[i] == '#') {
        tmpArr = returnNextStr(tmpArr, i, L, W);
      }
    }
    resltArr = tmpArr.slice();
    result++;
  }

  //出力
  console.log(result);
}