fun main(args: Array<String>) {
  val (h, w) = readLine()!!.split(" ").map { it.toInt() }
  val a = Array(h) { readLine()!! }
  val b = Array(w) { a.fold("") { buf, value -> buf + value[it] } }
  var row = Array<Boolean>(h) { true }
  for (i in 0 until h) {
    if (a[i].all { it == '.' }) row[i] = false
  }
  var col = Array<Boolean>(w) { true }
  for (j in 0 until w) {
    if (b[j].all { it == '.' }) col[j] = false
  }
  var ans = Array<MutableList<Char>>(h) { mutableListOf<Char>() }
  for (i in 0 until h) {
    for (j in 0 until w) {
      if (row[i] && col[j]) ans[i].add(a[i][j])
    }
    if (ans[i].isEmpty()) continue
    println(ans[i].joinToString(""))
  }
}
