import Control.Monad
import Data.List

getInts :: IO [Int]
getInts = do s <- getLine
             return $ map read $ words s

getLines :: Int -> IO [String]
getLines n = replicateM n $ getLine

trunc :: [String] -> [String]
trunc ws = filter (not . all (== '.')) ws

main = do [h, w] <- getInts
          bd <- getLines h
          mapM_ putStrLn $ trunc $ transpose $ trunc $ transpose bd