import Control.Applicative

main = do 
    [a, b] <- map read . words <$> getLine
    s <- lines <$> getContents
    mapM_ putStrLn (solver a b s)
    
solver :: Int -> Int -> [String] -> [String]
solver a b s = zipWith2 (f '#') s $ fmap2 (head . show) $ foldl1 (zipWith2 (+)) $ liftA3 (.) ud rl [fmap2 (fromEnum . ('#' == )) s]
    where
        ud = [shiftl s0, id, shiftr s0]
        rl = [(fmap (shiftl 0)), id, (fmap (shiftr 0))]
        fmap2 = fmap . fmap
        zipWith2 = zipWith . zipWith
        shiftl x xs = tail xs ++ [x]
        shiftr x xs = x : (init xs)
        s0 = take b (repeat 0)
        f a b c = if (a == b) then a else c