module Main where

import Control.Applicative
import Control.Monad
import Data.Maybe
import Data.Array
import Data.Char

(!?) :: Array (Int, Int) Char -> (Int, Int) -> Maybe Char
a !? (i, j)
    | bounds a `inRange` (i, j) = Just $ a ! (i, j)
    | otherwise                 = Nothing

f1 :: Array (Int, Int) Char -> (Int, Int) -> Int
f1 arr (i, j) = length $ filter (== '#') cs
  where
    ps = [(i + s, j + t) | s <- [-1, 0, 1], t <- [-1, 0, 1], any (/= 0) [s, t]]
    cs = catMaybes $ fmap (arr !?) ps

f2 :: Array (Int, Int) Char -> (Int, Int) -> Char
f2 arr (i, j)
    | Just '#' <- arr !? (i, j) = '#'
    | otherwise                 = intToDigit $ f1 arr (i, j)

main :: IO ()
main = do
    [h, w] <- fmap read . words <$> getLine :: IO [Int]
    arr <- fmap (listArray ((1, 1), (h, w)) . concat) $ replicateM h getLine
    forM_ [1 .. h] $ \s -> do
        let ps = range ((s, 1), (s, w))
        let line = fmap (f2 arr) ps
        putStrLn line