import Control.Monad
import Data.List
f s b=foldl'(\p q->max p (minimum[abs(x2-snd q)+abs(y2-fst q)|(y2,x2)<-b])) 0 s
main=do
 [h,w]<-map read.words<$>getLine
 sr<-replicateM h getLine
 let s=zip (concat sr) [(y,x)|y<-[1..h],x<-[1..w]]
     b=map snd$filter(\x->if fst x=='#' then True else False)s
 print$f (map snd(filter(\x->if fst x=='.' then True else False)s)) b