module Main where

import qualified Data.Vector as V
import           Data.List
import           Control.Applicative
import           Control.Monad

main :: IO ()
main = do
  [h, w] <- map read . words <$> getLine
  ss <- replicateM h $ getLine
  putStrLn . init $ f ss [(i, j) | j <- [0 .. h - 1], i <- [0 .. w - 1]] h w

f _ [] _ _ = ""
f ss (i:is) h w
  | (ss !! snd i) !! fst i == '#' = "#"
    ++ (if fst i == w - 1
        then "\n"
        else "")
    ++ f ss is h w
  | otherwise = show
    (length
     $ filter (== True)
     $ map
       (\i -> (ss !! snd i) !! fst i == '#')
       [(fst i + x, snd i + y)
       | x <- [-1, 0, 1]
       , y <- [-1, 0, 1]
       , fst i + x >= 0 && fst i + x < w
       , snd i + y >= 0 && snd i + y < h])
    ++ (if fst i == w - 1
        then "\n"
        else "")
    ++ f ss is h w
