import Control.Monad
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$maximum$map(\x->if fst x=='.' then minimum[abs(x2-snd(snd x))+abs(y2-fst(snd x))|(y2,x2)<-b] else 0)s