program grid_compression
  implicit none
  integer :: h, w, a(100,100) = 0, i, j, m = 0, x(100) = 0
  character(100) :: s
  read(*,*) h, w
  do i = 1, h
    read(*,*) s
    do j = 1, w
      if (s(j:j) == '#') a(i,j) = 1
    end do
  end do
  do j = 1, w
    if (all(a(1:h,j) == 0)) cycle
    m = m+1
    x(m) = j
  end do
  do i = 1, h
    if (all(a(i,1:w) == 0)) cycle
    do j = 1, m
      write(*,'(a)',advance='no') merge('#','.',a(i,x(j)) == 1)
    end do
    write(*,*)
  end do
end program grid_compression