Scanf.scanf "%d %d" (fun h w ->
    let a = Array.init h (fun _ -> Scanf.scanf " %s" (fun a -> a)) in
    let flagh = Array.init h (fun i ->
        let rec loop j =
            if j = w then false else
                if a.(i).[j] = '.' then loop (j + 1) else true
        in
        loop 0
    )
    in
    let flagw = Array.init w (fun j ->
        let rec loop i =
            if i = h then false else
                if a.(i).[j] = '.' then loop (i + 1) else true
        in
        loop 0
    )
    in
    for y = 0 to h - 1 do
        if flagh.(y) then (
            for x = 0 to w - 1 do
                if flagw.(x) then print_char a.(y).[x]
            done;
            print_newline ()
        )
    done
)