open Printf
open Scanf

let id x = x

let h, w = scanf "%d %d" (fun h w -> h, w)

let mat =
    Array.init h (fun i ->
        Array.init w (fun j ->
            scanf " %c" id
        )
    )

let () =
    for i = 0 to w - 1 do
        let b = ref true in
        for j = 0 to h - 1 do
            if mat.(j).(i) = '#' then b := false
        done;
        if !b then
            for j = 0 to h - 1 do
                mat.(j).(i) <- ' '
            done
    done;
    for j = 0 to h - 1 do
        let b = ref true in
        for i = 0 to w - 1 do
            if mat.(j).(i) = '#' then b := false
        done;
        if !b then
            for i = 0 to w - 1 do
                mat.(j).(i) <- ' '
            done
    done;
    for j = 0 to h - 1 do
        let b = ref false in
        for i = 0 to w - 1 do
            if mat.(j).(i) <> ' ' then
                (printf "%c" mat.(j).(i); b := true)
        done;
        if !b then printf "\n"
    done
