"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let H = cin.getInt(), W = cin.getInt();
    let B = [];
    for (let h = 0; h < H; h++) {
        let s = cin.getStr();
        for (let w = 0; w < W; w++) if (s[w] == '#') B.push({y:h, x:w});
    }
    let ans = 0;
    for (let b of B) {
        let min = Number.MAX_SAFE_INTEGER;
        let d0 = Math.abs(W - b.x) + Math.abs(0 - b.y);
        let d1 = Math.abs(W - b.x) + Math.abs(H - b.y);
        let d2 = Math.abs(0 - b.x) + Math.abs(H - b.y);
        let d3 = Math.abs(0 - b.x) + Math.abs(0 - b.y);
        if (min > d0 && d0 > 0) min = d0;
        if (min > d1 && d1 > 0) min = d1;
        if (min > d2 && d2 > 0) min = d2;
        if (min > d3 && d3 > 0) min = d3;
        if (ans < min && min < Number.MAX_SAFE_INTEGER) ans = min;
    }
    console.log(ans);
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0,this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));