Imports System
Imports System.Collections.Generic

Module ABC107B

	Dim Hmax,Wmax As Integer
	Dim data() As String
	
	Function IsHorAllWhite(ByVal idx As Integer)
		For w As integer = 0 To Wmax-1
			If data(idx)(w) = "#" Then Return False
		Next
		Return True	
	End Function

	Function IsVerAllWhite(ByVal idx As Integer)
		For h As integer = 0 To HMax-1
			If data(h)(idx) = "#" Then Return False
		Next
		Return True	
	End Function


	Sub Main()
		Dim inputs() As String = Console.ReadLine().Split()
		Hmax = Integer.Parse(inputs(0))
		Wmax = Integer.Parse(inputs(1))
		
		ReDim data(Hmax)
		For i As Integer = 0 To Hmax-1
			data(i) = Console.ReadLine()
		Next

		Dim LiveH As New List(Of Integer)
		Dim LiveW As New List(Of Integer)

		For h As Integer = 0 To Hmax-1
			If Not IsHorAllWhite(h)
				LiveH.Add(h)
			End If
		Next
		For w As Integer = 0 To Wmax-1
			If Not IsVerAllWhite(w)
				LiveW.Add(w)
			End If
		Next

		Dim ansH As Integer = LiveH.Count
		Dim ansW As Integer = LiveW.Count
		
		rem Console.WriteLine(ansH.ToString() & " " & ansW.ToString())
		For h As Integer = 0 To Hmax-1
			If Not LiveH.Contains(h) Then Continue For
			For w As Integer = 0 To Wmax-1
				If Not LiveW.Contains(w) Then Continue For
				Console.Write(data(h)(w))
			Next
			Console.WriteLine()
		Next
	End Sub
End Module

