import Data.Array

main = interact $ unlines . sol . lines

sol (s:ss) = [[g i j | j <- [1..w]] | i <- [1..h]]
  where
  [h,w] = map read $ words s
  t = listArray ((1,1),(h,w)) . map f . filter (>='#') $ concat ss
  f '.' = 0
  f '#' = 1
  g i j 
    | t!(i,j)==1  = '#'
    | otherwise   = head . show $ sum 
        [t!(i',j') | i' <- [max 1 (i-1)..min h (i+1)], j' <- [max 1 (j-1)..min w (j+1)]] 