fun main(args: Array<String>) = yorukatsu18b()

fun yorukatsu18b() {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }
    val grid = (1..h).map { readLine()!!.toCharArray() }

    val removeHorizon = grid.filter { it.any { it == '#' } }

    val removeVertical = (0 until w).mapNotNull { i ->
        val column = removeHorizon.map { it[i] }
        if (column.any { it == '#' }) column else null
    }

    val answer = removeHorizon.indices.joinToString(System.lineSeparator()) { y ->
        removeVertical.indices.map { x -> removeVertical[x][y] }.joinToString("")
    }

    println(answer)
}
