import Control.Monad
import Data.List
import Data.Char
import Data.Array.Unboxed

main=do
    [h,w]<-map read.words<$>getLine::IO[Int]
    mp <- listArray ((0,0),(h+1,w+1)).
            flip (++) (replicate (w+3) 'x'). (++) (replicate (w+1) 'x').
            concat.map ((++) "xx")<$> replicateM h getLine::IO (Array (Int,Int) Char)
    mapM_ putStrLn $ sep w $ filter (/='x') $ map (snd.mine mp) $ assocs mp

sep::Int -> [a] -> [[a]]
sep w [] = []
sep w s = liftM2 (:) (take w) (sep w.drop w) s

mine :: (Array (Int,Int) Char) -> ((Int,Int), Char) -> ((Int,Int), Char)
mine _ e@(hw,'#') = e
mine _ e@(hw,'x') = e
mine mp (hw@(h,w), _) =
    (,) hw $ intToDigit $ length $
    filter (=='#') $ map ((!) mp) [(h-1,w-1),(h,w-1),(h+1,w-1),(h-1,w),(h+1,w),(h-1,w+1),(h,w+1),(h+1,w+1)]