"use strict";
function I(t,i){this._s=t.split("\n"),this._c=0,this._l=0,this._f=i||Number}I.prototype.a=function(t){var i=this._s[this._l];if(i){var s=i.trim().split(" "),h=s[this._c];return this._c++,s.length===this._c&&(this._c=0,this._l++),t?t(h):this._f(h)}},I.prototype.l=function(t){var i=this._s[this._l];if(i)return this._c=0,this._l++,i.split(" ").map(t||this._f)},module.exports=I;

function main(input) {
  var o = new I(input);

  var h = o.a();
  var w = o.a();

  var a = [];
  for (var i = 0; i < h; i++) {
    a.push(o.a(String).split(""));
  }

  var stack = [];
  for (var i = 0; i < h; i++) {
    for (var j = 0; j < w; j++) {
      if (a[i][j] === "#") {
        stack.push({i, j});
      } 
    }
  }

  var count = 0;
  // console.log({a, stack})
  while (stack.length > 0) {
    count += 1;
    var newStack = [];
    var len = stack.length;
    for (var k = 0; k < len; k++) {
      var grid = stack.pop();
      var i = grid.i;
      var j = grid.j;
      // console.log({i, j})
      if (i - 1 >= 0 && i - 1 < h && a[i - 1][j] === ".") {
        a[i - 1][j] = "#";
        newStack.push({i: i - 1, j: j});
      }
      if (i + 1 >= 0 && i + 1 < h && a[i + 1][j] === ".") {
        a[i + 1][j] = "#";
        newStack.push({i: i + 1, j: j});
      }
      if (j - 1 >= 0 && j - 1 < w && a[i][j - 1] === ".") {
        a[i][j - 1] = "#";
        newStack.push({i: i, j: j - 1});
      }
      if (j + 1 >= 0 && j + 1 < w && a[i][j + 1] === ".") {
        a[i][j + 1] = "#";
        newStack.push({i: i, j: j + 1});
      }
    }

    stack = newStack;
  }

  console.log(count - 1);  
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));
