import Data.Array
import Data.Char
import Control.Monad

--面倒なので、一マス大きい入力にすること。
trans::Array Int (Array Int Char) -> (Int,Int)-> Array Int(Array Int Char)
trans ar (h,w) = listArray (1,h) [listArray (1,w) [   if (ar!i)!j == '#'then '#' else  (intToDigit.length.(filter (\x-> x== '#')))  [(ar!x!y)|(x,y)<-[(i+1,j),(i+1,j+1),(i,j+1),(i-1,j+1),(i-1,j),(i-1,j-1),(i,j-1),(i+1,j-1)]]           |j<-[1..w]] |i<-[1..h]]


wrapper::[[Char]]->(Int,Int)-> Array Int (Array Int Char)
wrapper ls (h,w)= listArray (0,h+1) (map (listArray (0,w+1)) (  (take (w+2) (repeat '.')) : (map (\cs -> '.':cs++ ['.'] ) ls)++ [(take (w+2) (repeat '.'))] ) )

getter::Int -> IO [[Char]]
getter 0 =return []
getter n = do
  cs<-getLine
  rest<-getter (n-1)
  return (cs:rest)

printer::Array Int (Array Int Char)->IO()
printer ar = forM_ (map elems (elems ar)) oneline
            where oneline ls = do
                            putStr ls
                            putStr "\n"

main::IO()
main =do
  d<-getLine
  let h:w:[]= map read (words d)
  lsdat<-getter h
  let input = wrapper lsdat (h,w)
  printer (trans input (h,w))