{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Data.Char (intToDigit)

main :: IO ()
main = do
  [h, w] <- map read . words <$> getLine
  sss <- lines <$> getContents
  putStr . unlines $ solve h w sss

solve :: Int -> Int -> [[Char]] -> [[Char]]
solve h w sss = map (map count) [[(i, j) | i <- [0 .. w - 1]] | j <- [0 .. h - 1]]
  where
    count :: (Int, Int) -> Char
    count (i, j) = if sss !! j !! i == '#'
      then '#'
      else  intToDigit . length $ filter isBomb [(i + x, j + y) | x <- [-1 .. 1], y <- [-1 .. 1]]
    isBomb :: (Int, Int) -> Bool
    isBomb (x, y) = 0 <= x && x < w && 0 <= y && y < h && sss !! y !! x == '#'
