import Control.Applicative
import Control.Monad
import Data.Char

main = do
  [h, w] <- map read . words <$> getLine
  g <- replicateM h getLine
  mapM putStrLn . solve $ g

solve :: [String] -> [String]
solve g = [[f i j | j <- [0..w-1]] | i <- [0..h-1]]
  where
    h = length g
    w = length . head $ g

    inside :: Int -> Int -> Bool
    inside i j = 0 <= i && i < h && 0 <= j && j < w

    f :: Int -> Int -> Char
    f i j
      | g !! i !! j == '#' = '#'
      | otherwise          = intToDigit . length . filter (\(ii, jj) -> g !! ii !! jj == '#') $ adj
      where adj = [(ii, jj) | ii <- [i-1..i+1], jj <- [j-1..j+1], inside ii jj]
