import Control.Applicative
import Control.Monad
import Data.List


main = do
    [h, w] <- map read . words <$> getLine
    lines <- replicateM h getLine
    let ans = solve w lines
    forM_ [0..(length ans - 1)] $ \i -> do
        putStrLn (ans !! i)

solve :: Int -> [String] -> [String]
solve w = compressCol w . compressRow

compressRow :: [String] -> [String]
compressRow = filter (\line -> not ((length $ group line) == 1 && (head line == '.')))

compressCol :: Int -> [String] -> [String]
compressCol w lines =
    let getCols 0 _ _ = []
        getCols n k lines = map (\line -> line !! (k - n)) lines : getCols (n - 1) k lines
        cols = getCols w w lines
        compressedCols = compressRow cols
    in getCols (length lines) (length lines) compressedCols
