import Control.Monad (replicateM,guard)
import Data.List (groupBy)

main = do
    [h,w] <- fmap read . words <$> getLine
    xs <- replicateM h getLine
    let nns (x,y) = do
        dx <- [-1,0,1]
        dy <- [-1,0,1]
        let x'=x+dx
        let y'=y+dy
        guard $ not $ x==x' && y==y'
        guard $ 1<=x' && x'<=w
        guard $ 1<=y' && y'<=h
        return (x',y')
    let ys = [ ((x,y), if xs.>(x,y)=='#'
                            then "#"
                            else show . countBomb $ (xs.>) <$> nns (x,y)) | y <- [1..h], x <- [1..w] ]
    mapM_ putStrLn $ concatMap snd <$> groupBy (\((_,y1),_) ((_,y2),_) -> y1==y2) ys

countBomb = length . (filter ('#'==))
xs .> (x,y) = (xs !! (y-1)) !! (x-1)