fun main(args: Array<String>) {
    val (H, W) = readLine()!!.split(" ").map(String::toInt)
    val grid = Array(H) { readLine()!! }
    var newLine = false
    for (h in 0 until H) {
        var skip = true
        for (w in 0 until W) {
            var put: Boolean = '#' in grid[h]
            for (i in 0 until H) {
                if (grid[i][w] == '#') break
                if (i == H - 1) put = false
            }


            if (put) {
                if (newLine) {
                    println()
                    newLine = false
                }
                print(grid[h][w])
                skip = false
            }
        }
        if (!skip) newLine = true
    }
}