import Data.List

main :: IO ()
main = do
  [h,w] <- map read . words <$> getLine :: IO [Int]
  l <- lines <$> getContents 
  let bs = concat $ map (\g -> boms (fst g) (snd g)) $ zip [1..h] l 
  let grid =  [((i,j),v) | i <- [1..h], j <- [1..w], let v = (l !! (i-1)) !! (j-1)]
  putStr $ split (makeLine grid bs)  w
 
boms :: Int -> String -> [(Int, Int)]
boms h l = map (\i -> (h,i+1)) $ elemIndices '#' l

around :: (Int, Int) -> [(Int,Int)]
around (i,j) = [(i-1,j-1), (i-1,j), (i-1,j+1), (i,j-1), (i,j+1), (i+1,j-1), (i+1,j), (i+1,j+1)]

makeLine :: [((Int,Int),Char)] -> [(Int,Int)]-> String
makeLine [] _ = ""
makeLine (x:xs) bs
  |snd x == '#'= ['#'] ++ (makeLine xs bs)
  |otherwise =
    let number = length $ filter (`elem` bs) $ around (fst x) 
      in show number ++ makeLine xs bs

  
split :: String -> Int -> String
split "" _ = ""
split xs w = take w xs ++ "\n" ++ split (drop w xs) w