import Data.Char

main = do
    [h,w] <- map read . words <$> getLine
    ss <- lines <$> getContents
    let solve y = map (flip count y) [0..w-1]
        count x y
            | sample x y == '#' = '#'
            | otherwise = intToDigit . length $ filter (=='#') [sample (x+x') (y+y') | x' <- [-1..1], y' <- [-1..1]]
        sample x y
            | x < 0 || w <= x = '.'
            | y < 0 || h <= y = '.'
            | otherwise = ss!!y!!x
    mapM_ putStrLn $ map (solve) [0..h-1]
