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