import Data.List(sortBy, groupBy)
import Data.Ord(comparing)
import Control.Monad(forM_)

type Point = (Int, Int)
type Row = [(Int, String)]

type Score = (Point, String)

main = do
  ns <- lines <$> getContents
  let h = read $ head $ words $ head ns
  let w = read $ last $ words $ head ns
  let lines = tail ns
  let res = solve h w lines
  forM_ res putStrLn 

newRow :: String -> Row
newRow src = filter (\(y, v) -> v == "#") $ zipWith (\n v -> (n, if v == '.' then "0" else "#")) [0 .. (subtract 1 $ length src)] src

makePs :: Score -> [Point]
makePs ((x, y), v) = [(x', y') | x'<- [(subtract 1 x) .. (x + 1)], y'<- [(subtract 1 y) .. (y + 1)], (x,y) /= (x', y')]

sortPs :: Point -> Point -> Ordering
sortPs (x1, y1) (x2, y2)
  | x1 < x2 = LT
  | and [x1 == x2, y1 < y2] = LT
  | x1 > x2 = GT
  | and [x1 == x2, y1 > y2] = GT
  | and [x1 == x2, y1 == y2] = EQ

eqPs :: Point -> Point -> Bool
eqPs (x1, y1) (x2, y2)
  | and [x1 == x2, y1 == y2] = True
  | otherwise = False

sortedPs :: [String] -> [[Point]]
sortedPs s = groupBy eqPs $ sortBy sortPs $ concatMap makePs $ getMs s

countPs :: [[Point]] -> [Score]
countPs ps = zipWith (\p c -> ((head p), show c)) ps (map length ps)

preChoose :: Point -> [Score] -> Score
preChoose p ss
  | 0 < length res = head res
  | otherwise = ((0, 0), "0")
  where
    res = filter (\s -> p == (fst s)) ss

choose :: [Score] -> [Score] -> Point -> Score
choose ms ss p
  | snd v == "#" = v
  | otherwise = preChoose p ss
  where
    v =  preChoose p ms

grByP :: Score -> Score -> Bool
grByP ((ax, ay), av) ((bx, by), bv) 
  | ax == bx = True
  | otherwise = False

toShow :: [Score] -> String
toShow ss = concat $ map (\s -> snd s) ss

solve :: Int -> Int -> [String] -> [String]
solve h w line = map toShow ls
  where
    ps = [(x, y) | x <- [0 .. subtract 1 h], y <- [0 .. subtract 1 w]]
    ms = getMs line
    ss = countPs (sortedPs line)
    res = map (choose ms ss) ps
    ls = groupBy grByP res

ps = [(x :: Int , y :: Int ) | x <- [0 .. 2] , y <- [0 .. 2]]
ms = getMs ["#..", ".#.", "..#"]
ss = countPs $ sortedPs ["#..", ".#.", "..#"]

getMs :: [String] -> [Score]
getMs ls = wrap (zip [0 .. length ls] (map fspl ls)) []

wrap :: [(Int,[(Int, Char)])] -> [Score] -> [Score]
wrap [] acc = acc
wrap ns acc = wrap (tail ns) (elm ++ acc)
  where 
    h = head ns
    x = fst h
    src = snd h
    elm = conv x src [] 

conv :: Int -> [(Int, Char)] -> [Score] -> [Score]
conv x [] acc = acc
conv x src acc = conv x (tail src) acc'
  where
    h = head src
    val = snd h
    acc' = if val == '#' then ((x, fst h), "#") : acc
          else acc 

fspl :: String -> [(Int, Char)]
fspl s = zip [0 .. length s] s