object Main extends App {
  val in = new java.util.Scanner(System.in)
  val H, W = in.nextInt
  val grid = Array.fill(H)(in.next)
  def removeAndRotate(a: Array[String]): Array[String] =
     a.filter(_.exists(_ == '#')).map(_.toArray).transpose.map(_.mkString)

  println(removeAndRotate(removeAndRotate(grid)).mkString("\n"))
}