import scala.io.StdIn._
object Main {
  def main(args: Array[String]): Unit = {
    val HW = readLine.split("\\s+").toSeq.map{_.toInt}
    val H = HW(0)
    val W = HW(1)
    val matrix = for(i <- 1 to H) yield readLine
    val row = for(i <- 0 to H - 1 if matrix(i).exists{_ == '#'}) yield i
    val column = for(i <- 0 to W - 1 if matrix map {_(i)} exists {_ == '#'}) yield i
    for(i <- row; n <- column)
    {
      print(matrix(i)(n))
      if(n == W - 1){
        print("\n")
      }
    }
  }
}
