module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

import qualified Data.Set as Set

------------------------------------------

dir = zip [1, 1, 0, -1, -1, -1, 0, 1] [0, 1, 1, 1, 0, -1, -1, -1]

main :: IO ()
main = do
  [h, w] <- readInts
  raw <- zipWith (\a -> map (\(b, c) -> (a, b, c))) [0..] <$> replicateM h (getLine >>= return . zip [0..])
  let s = map (\(a,b,_) -> (a, b)) $ concat $ map (filter (\(_,_,c) -> c == '#')) raw
      m = Set.fromList s
      out x y
        | x >= h = return ()
        | y >= w = putStrLn "" >> out (x+1) 0
        | otherwise = do
          if Set.member (x, y) m then putStr "#"
          else do
            let np = zipWith (\(dx, dy) (x, y) -> (x+dx, y+dy)) dir (repeat (x, y))
                ans = length $ filter (flip Set.member m) np
            putStr $ show ans
          out x (y+1)
  out 0 0
  return ()


------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"
