program sample
    implicit none
    character(100)::s
    character(100),allocatable::t(:),ans(:)
    integer(8) :: i,j,m,n,h,w,a,b,c
    integer(8),allocatable :: x(:,:),y(:)
    read(*,*)h,w
    allocate(t(h))
    t(1)='0'
   
    a=0
    b=0
    do i=1,h
        a=0
        read(*,*) s
        do j=1,w
            if(s(j:j) .eq. '#')then
               a=1 
            end if
        end do
        if(a==1)then
            b=b+1
            t(b)=s
            
        end if
    end do
    
    c=0
    do j=1,w
        a=0
        do i=1,b
            if(t(i)(j:j) .eq. '#')then
                a=1 
            end if
        
        end do
        if (a==1)then
            c=c+1
            do i=1,b
                t(i)(c:c)=t(i)(j:j)
            end do
        end if


    end do
    
    do i=1,b
        write(*,'(a)')t(i)(1:c)
        
    end do
   
  
    stop
end program sample
  


  

