import           Control.Monad
import qualified Data.ByteString.Char8         as B
import qualified Data.Vector                   as V
import           Data.Char

main = do
  [h, w] <- map read . words <$> getLine
  s      <- V.replicateM h B.getLine
  V.mapM_ B.putStrLn $solve h w s
solve h w s = V.generate h f where
  f i = B.pack $map g [0 .. w - 1]   where
    g j = if B.index (s V.! i) j == '#'
      then '#'
      else intToDigit $ length
        [ ()
        | di <- [-1 .. 1]
        , dj <- [-1 .. 1]
        , let (i', j') = (i + di, j + dj)
        , 0 <= i'
        , i' < h
        , 0 <= j'
        , j' < w
        , B.index (s V.! i') j' == '#'
        ]
