// scan tuple
let scan1 f = stdin.ReadLine() |> f
let scan2 f = stdin.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1]))
let scan3 f = stdin.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2]))
let scan4 f = stdin.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2], a.[3]))
// scan vec and matrix (using Array)
let scanVecH f = stdin.ReadLine().Split() |> Array.map f
let scanVecV f n = [| for i in 1..n -> stdin.ReadLine() |> f |]
let scanMatrix f n = [| for i in 1..n -> stdin.ReadLine().Split() |> Array.map f |]
let scanCharMatrix n = [| for i in 1..n -> stdin.ReadLine().ToCharArray() |]
// vec tools
let transpose (m:'a [][]) = 
  let h,w = Array.length m, Array.length m.[0]
  [| for i in 0..w-1 -> [|0..h-1|] |> Array.map (fun j -> m.[j].[i]) |]

let h, w = scan2 int

scanCharMatrix h
|> Array.filter (Array.exists ((=) '#'))
|> transpose
|> Array.filter (Array.exists ((=) '#'))
|> transpose
|> Array.map (fun a -> Array.map string a |> String.concat "")
|> String.concat "\n"
|> printfn "%s"
