program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: h,w,i,j
    character(1),allocatable:: a(:,:),ans(:,:)

    read*, h,w
    allocate(a(w,h),ans(w,h))
    a(:,:) = ' '
    ans(:,:) = ' '

    block
        character(w):: inpt_a
        integer(int32):: diff=0
        do i=1,h
            read*, inpt_a
            if (all_dot(inpt_a)) then
                diff=diff+1
                cycle
            end if
            do j=1,w
                a(j,i-diff) = inpt_a(j:j)
            end do
        end do
    end block

    block
        character(h):: ah
        integer(int32):: diff

        do j=1,w
            diff=0
            do i=1,h
                ah(i:i) = a(j,i)
            end do
            if(all_dot(ah))then
                diff=diff+1
                cycle
            end if
            ans(j,:) = a(j+diff,:)
        end do
    end block
    
    block
        character(w):: ansc
        do i=1,h
            do j=1,w
                ansc(j:j) = ans(j,i)
            end do
            if (len_trim(ansc) == 0) cycle
            print'(a)', trim(ansc)
        end do
    end block

contains
        function all_dot(s) result(ret)
            character(*):: s
            logical:: ret
            integer(int32):: l,i

            l = len(s)
            ret = .true.
            do i=1,l
                if (s(i:i) == '#') ret=.false.
            end do
        end function
end program name