fun main(args: Array<String>) {
    abc107b()
}

fun abc107b() {
    val (h, w) = readLine()!!.split(" ").map { it.toInt() }
    val aList = (1..h).map { readLine()!!.toCharArray() }

    val horizontalOutIndex = aList
        .mapIndexed { index, chars -> Pair(index, chars.any { it == '#' }) }
        .filter { it.second }.map { it.first }

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

    val answer = aList.mapIndexed { indexChars, chars ->
        if (horizontalOutIndex.contains(indexChars)) {
            chars.mapIndexed { indexChar, c ->
                if (verticalOutIndex.contains(indexChar)) c else null
            }.filterNotNull().joinToString(separator = "")
        } else null
    }.filterNotNull()

    println(answer.joinToString(separator = System.lineSeparator()))
}
