import Data.Array.IO
import Control.Monad

main = do
  (h:w:_) <- getLine >>= return . (map read) . words :: IO [Int]
  ms <- newArray ((0, 0), (w+1, h+1)) 0 :: IO (IOArray (Int, Int) Int)

  forM_ [1..h] $ \y -> do
    ln <- getLine
    forM_ [1..w] $ \x -> do
      when (ln!!(x-1) == '#') (writeArray ms (x,y) 1)

  let dir = [(1,0), (1,1), (0,1), (-1,1), (-1,0), (-1,-1), (0,-1), (1,-1)]
  forM [1..h] $ \y -> do
    t <- forM [1..w] $ \x -> do
      r <- readArray ms (x, y)
      s <- forM [0..7] $ \k -> do
        let (dx,dy) = dir!!k
        c <- readArray ms (x+dx, y+dy)
        return c
      return $ if r==1 then "#" else (show (sum s))
    putStrLn (concat t)
          
