module.exports=function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=0)}([function(t,e,i){i(1)(i(3).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(t,e,i){var n=i(2);t.exports=function(t){for(var e=t[0].split(" "),i=Number(e[0]),r=Number(e[1]),s=[],o=0,u=new n(1),d=0;d<i;d++){for(var f=t[d+1].split(""),l=0;l<r;l++)"#"==f[l]?u.enq({x:l,y:d,dist:0}):o+=1;s.push(f)}for(;u.size>0;){var c=u.deq();if("."==s[c.y][c.x]||0==c.dist){if("."==s[c.y][c.x]&&(s[c.y][c.x]="#",o-=1),o<=0)return void console.log(c.dist);c.x+1<r&&"#"!=s[c.y][c.x+1]&&u.enq({x:c.x+1,y:c.y,dist:c.dist+1}),c.x-1>=0&&"#"!=s[c.y][c.x-1]&&u.enq({x:c.x-1,y:c.y,dist:c.dist+1}),c.y+1<i&&"#"!=s[c.y+1][c.x]&&u.enq({x:c.x,y:c.y+1,dist:c.dist+1}),c.y-1>=0&&"#"!=s[c.y-1][c.x]&&u.enq({x:c.x,y:c.y-1,dist:c.dist+1})}}}},function(t,e,i){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1e4;this.size=0,this.items=[],this.ind=0,this.maxGap=t}enq(t){this.size+=1,this.items.push(t),this.items.size-this.ind>this.maxGap&&(this.items=this.items.slice(this.ind))}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}}},function(t,e){t.exports=require("fs")}]);