import Data.List
k i=(drop(i-1)).(take(i+2))
t s i j h=(if j<1 then [] else[k i (s!!(j-1))])++[k i(s!!j)]++(if (j+1)>=h then [] else [k i(s!!(j+1))])
u s =(sum.map (length.elemIndices '#'))s
f s j h w= if j>=h then[]else[g s 0 j h w]++f s (j+1) h w
g s i j h w=if i>=w then[]else (if (s!!j)!!i =='#'then"#"else(show(u(t s i j h))))++g s (i+1) j h w
main=do
 [h,w]<-map read.words<$>getLine
 s<-lines<$>getContents
 putStr$unlines$f s 0 h w