import Control.Monad

main :: IO ()
main = do
  [h, w] <- map read . words <$> getLine
  ss <- replicateM h getLine
  let bs = [(x, y) | x <- [0..(w - 1)], y <- [0..(h - 1)], (ss !! y) !! x == '#']
  let solve x y = head . show . sum $ map (\n -> if abs (x - fst n) <= 1 && abs (y - snd n) <= 1 then 1 else 0) bs
  print [[if (ss !! y) !! x == '#' then '#' else solve x y | x <- [0..(w - 1)]] | y <- [0..(h - 1)]]
