fun main(args: Array<String>) {
    val (h, w) = readLine()?.split(" ")?.map(String::toInt) ?: return
    val squares = mutableListOf<MutableList<Char>>()
    repeat(h) {
        val line = readLine() ?: return
        if (line.any { it == '#' }) {
            squares.add(line.toMutableList())
        }
    }
    var j = w - 1
    while (j >= 0) {
        if (squares.all { line ->
                line[j] == '.'
            }) {
            squares.forEach {
                it.removeAt(j)
            }
        }
        j--
    }
    println(squares.joinToString(separator = "\n") { it.joinToString(separator = "") })
}
