object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val H, W = sc.nextInt()
  val squares = Array.fill(H)(sc.next().toCharArray).filterNot(_.forall(_ == '.'))
  val rotated = 0.until(W).map(i => squares.map(_ (i))).toArray.filterNot(_.forall(_ == '.'))
  rotated.head.indices.map(i => rotated.map(_ (i))).foreach(line => println(new String(line)))
}
