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 =  [c |i <- [1..h], 
                  j <- [1..w], 
                  let v = (l !! (i-1)) !! (j-1),
                  let c = if v == '#' then v else head $ show $ length $ filter (`elem` bs) $ around (i,j)]
  putStr $ aligne grid w
    where 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)] 
          boms h l = map (\i -> (h,i+1)) $ elemIndices '#' l
 
aligne :: String -> Int -> String
aligne [] _ = ""
aligne xs w = take w xs ++ "\n" ++ aligne (drop w xs) w
