'use strict';
function main(i) {
  i = i.split('\n');
  const H = Number(i[0].split(' ')[0]);
  const W = Number(i[0].split(' ')[1]);
  const array = [];

  for (let j = 0; j < H ; j ++) {
    array.push(i[j + 1].split(''));
  }

  const newArray = array.map(a => a.map(b => {
    if (b === '#') {
      return true;
    } else {
      return false;
    }
  }));

  function isBlack (array) {
    let result = 1;
    array.forEach(item => {
      if (item) {
        result *= 1;
      } else {
        result *= 0;
      }
    });
    return result === 1;
  }

  let count = 0;

  while (newArray.filter(isBlack).length < H) {
    let blacks = [];
    for (let j = 0; j < H; j ++) {
      for (let k = 0; k < W; k ++) {
        if (newArray[j][k]) {
          blacks.push({
            h: j,
            w: k,
          });
        }
      }
    }

    blacks.forEach(black => {
      if (black.h > 0) {
        newArray[black.h - 1][black.w] = true;
      }
      if (black.h < H - 1) {
        newArray[black.h + 1][black.w] = true;
      }
      if (black.w > 0) {
        newArray[black.h][black.w - 1] = true;
      }
      if (black.w < W - 1) {
        newArray[black.h][black.w + 1] = true;
      }
    });

    count += 1;
  }

  console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));