let rec for_fold a b v f = if a >= b then v else for_fold (a+1) b (f v a) f
let for_filter a b f =
  for_fold a b [] (fun s i -> if f i then i::s else s) |> List.rev

let () =
  Scanf.scanf "%d %d" @@ fun h w ->
  let a = Array.init h (fun _ -> Scanf.scanf " %s" (fun x -> x)) in
  let rows = for_filter 0 h (fun i ->
    for_fold 0 w false (fun b j -> b || a.(i).[j] = '#'))
    |> Array.of_list in
  let columns = for_filter 0 w (fun j ->
    for_fold 0 h false (fun b i -> b || a.(i).[j] = '#'))
    |> Array.of_list in
  Array.iter (fun i ->
    String.init (Array.length columns) (fun j -> a.(i).[columns.(j)])
    |> print_endline) rows
