import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  [h,w] <- map (read::String->Int) . words <$> getLine
  as <- lines <$> getContents
  (putStrLn .unlines .transpose .comp .transpose .comp) as

comp ls = map snd $ filter ((==False).fst) $zip (map (all (=='.')) ls) ls