main = do
  [h,w] <- map read . words <$> getLine 
  s <- lines <$> getContents 
  mapM putStr (solve (h,w) s)

type Pos = (Int,Int)

count :: Pos -> Pos -> [String] -> Char
count (h,w) (n,m) s = 
  if s !! n !! m == '#' then '#' else
  head $ show $ length $ filter (=='#') [s !! p !! q | i <- [-1,0,1],j <- [-1,0,1],not (i == 0 && j == 0),let p = n+i,let q = m+j,0 <= p,p<h,0<=q,q<w]

solve ::Pos -> [String] -> [String]
solve (h,w) s = [[count (h,w) (i,j) s] | i <- [0..h-1],j <-[0..w -1]]