private fun readInts() = readLine()!!.split(" ").map { it.toInt() }.toList()

fun main(args: Array<String>) {
    val (H, W) = readInts()
    val a = (0 until H).map { readLine()!! }

    var newMap: List<String>
    newMap = a.filter { it.contains("#") }.toList()
    newMap = (0 until newMap[0].length)
            .filter { v -> newMap.any { s -> s[v] == '#' } }
            .let { indexes ->
                newMap.map { str -> str.filterIndexed { index, str -> indexes.contains(index) } }
            }

    newMap.forEach { println(it) }
}