import Control.Monad
import Data.List

solve :: [[Bool]] -> [String] -> [String]
solve [] [] = []
solve (m:ms) (f:fs) = map snd (filter fst $ zip m f) : solve ms fs

main :: IO ()
main = do
  [h, w] <- map read . words <$> getLine
  fields <- replicateM h getLine
  let rows = elem '#' <$> fields
  let columns = elem '#' <$> transpose fields
  let marks = [[x && y | y <- columns] | x <- rows]
  mapM_ putStrLn $ filter (not . null) $ solve marks fields