import scala.io.StdIn

object Main extends App {

  val Array(h, w) = StdIn.readLine().split(" ").map(_.toInt)

  val a = for (i <- 0 until h) yield StdIn.readLine()

  val exH = a.zipWithIndex.map(e => if (e._1.forall(c => c == '.')) -1 else e._2).filter(_ != -1)
  
  def allWhite(col: Int) = a.forall(p => p(col) == '.')

  val exW = (for (j <- 0 until w) yield if (allWhite(j)) -1 else j).filter(_ != -1)

  for (r <- 0 until h if exH.exists(_ == r)) {
    for (c <- 0 until w if exW.exists(_ == c)) {
      print(a(r)(c))
    }
    println("")
  }

}
