module Main where
import Data.Char

main = interact $ printer . solver . parser
int = read :: String -> Int
count a bs = length $ filter (==a) bs
split n ls = map (take n) $ takeWhile (/=[]) $ iterate (drop n) ls

printer = unlines 
parser input = (int hs, int ws, fs) 
  where
    (hs:ws:fs) = words input

solver :: (Int,Int,[String]) -> [String]
solver (h,w,fs) = 
  split w $
  [
    if (fs!!i!!j) == '#'
    then
    '#'
    else
    intToDigit $
    count '#' [(fs!!ii!!jj)
              |ii<-[(i-1)..(i+1)],0<=ii,ii<h,
               jj<-[(j-1)..(j+1)],0<=jj,jj<w]
  |i<-[0..(h-1)],j<-[0..(w-1)]
  ]
    
  
