main :: IO ()
main = do
  [h,w] <- map read . words <$> getLine :: IO [Int]
  as <- concat . lines <$> getContents
  let xy = [(x,y)| y<-[1..h], x<-[1..w]]
  let grid = zip xy as :: [((Int,Int),Char)]
  putStr $ trim $ rmdpl $ draw grid grid h w


isSkip :: [((Int,Int),Char)] -> ((Int,Int),Char) -> Int -> Int -> Bool
isSkip as ((x,y),v) h w = 
  let 
    vert = [() | a<-as, (fst $ fst a) == x, v == '.', snd a == v]
    hori = [() | a<-as, (snd $ fst a) == y, v == '.', snd a == v]
    in 
      length vert == h || length hori == w

draw :: [((Int,Int),Char)] -> [((Int,Int),Char)] -> Int -> Int -> String
draw [] _ _ _ = ""
draw (a:as) xs h w
  | (isSkip xs a h w) && ((fst $ fst a) == w) = "\n" ++ draw as xs h w
  | isSkip xs a h w                         = "" ++ draw as xs h w
  | (not $ (isSkip xs a h w)) && ((fst $ fst a) == w) = [snd a] ++ "\n" ++ draw as xs h w
  | otherwise = [snd a] ++ draw as xs h w  

trim :: String -> String
trim xs
  | head xs == '\n' = trim $ tail xs
  | last xs == '\n' = trim $ init xs
  | otherwise = xs

rmdpl :: String -> String
rmdpl [] = []
rmdpl [x] = [x]
rmdpl (x:y:xs) 
  | (x=='\n' && y=='\n') = x : rmdpl xs
  | otherwise = x :  rmdpl (y:xs)
