fun main(args: Array<String>) {
    var (H, W) = listOfInt()
    val M = mutableListOf<MutableList<Int>>()
    for (h in 0 until H) {
        M.add(next().map{ if (it == '.') 0 else 1 }.toMutableList())
    }
    var f = false
    fun yoko() {
        for (h in (0 until H).reversed()) {
            var sum = 0
            for (w in 0 until W) sum += M[h][w]
            if (sum == 0) {
                M.removeAt(h)
                H--
                f = true
            }
        }
    }
    fun tate() {
        for (w in (0 until W).reversed()) {
            var sum = 0
            for (h in (0 until H).reversed()) sum += M[h][w]
            if (sum == 0) {
                for (h in (0 until H).reversed()) M[h].removeAt(w)
                W--
                f = true
            }
        }
    }
    do {
        f = false
        yoko()
        tate()
    } while (f)
    repeat(H) {
        println(M[it].joinToString(separator = "") { if (it == 0) "." else "#" })
    }
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
