h,w = map(int,input().split())

A = [list(map(str,input())) for i in range(h)]

for k in range(max(h,w)):

    counter = 0

    for i in range(h):

        if '#' not in A[i-counter]:

            del(A[i-counter:i-counter+1])

            counter += 1

            h -= 1

        if i-counter >= h-1:

            break

    counter = 0

    B = [list(row) for row in zip(*A)]

    for j in range(w):

        if '#' not in B[j-counter]:

            del(B[j-counter:j-counter+1])

            counter += 1

            w -= 1

        if j-counter >= w-1:

            break

    A = [list(row) for row in zip(*B)]

for row in A:

    print(*row, sep='')

h,w=list(map(int,input().split()))

A=[eval(input()) for i in range(h)]

B=[]

for i in range(h):

    if '#' in A[i]:

        B.append(A[i])

def rot(X):

    C=[]

    for l in range(len(X[0])):

        C_row=[]

        for m in X:

            C_row.append(m[l])

        C.append(C_row)

    return C

D=rot(B)

E=[]

for i in range(w):

    if '#' in D[i]:

        E.append(D[i])

F=rot(E)

for f in F:

    print((''.join(f)))
h, w = map(int, input().split())
A = [list(map(str, input())) for i in range(h)]
for k in range(max(h, w)):
    counter = 0
    for i in range(h):
        if "#" not in A[i - counter]:
            del A[i - counter : i - counter + 1]
            counter += 1
            h -= 1
        if i - counter >= h - 1:
            break
    counter = 0
    B = [list(row) for row in zip(*A)]
    for j in range(w):
        if "#" not in B[j - counter]:
            del B[j - counter : j - counter + 1]
            counter += 1
            w -= 1
        if j - counter >= w - 1:
            break
    A = [list(row) for row in zip(*B)]
for row in A:
    print(*row, sep="")

h, w = list(map(int, input().split()))
A = [eval(input()) for i in range(h)]
B = []
for i in range(h):
    if "#" in A[i]:
        B.append(A[i])


def rot(X):
    C = []
    for l in range(len(X[0])):
        C_row = []
        for m in X:
            C_row.append(m[l])
        C.append(C_row)
    return C


D = rot(B)
E = []
for i in range(w):
    if "#" in D[i]:
        E.append(D[i])
F = rot(E)
for f in F:
    print(("".join(f)))

-h, w = map(int, input().split()) -A = [list(map(str, input())) for i in range(h)] -for k in range(max(h, w)): -    counter = 0 -    for i in range(h): -        if "#" not in A[i - counter]: -            del A[i - counter : i - counter + 1] -            counter += 1 -            h -= 1 -        if i - counter >= h - 1: -            break -    counter = 0 -    B = [list(row) for row in zip(*A)] -    for j in range(w): -        if "#" not in B[j - counter]: -            del B[j - counter : j - counter + 1] -            counter += 1 -            w -= 1 -        if j - counter >= w - 1: -            break -    A = [list(row) for row in zip(*B)] -for row in A: -    print(*row, sep="") +h, w = list(map(int, input().split())) +A = [eval(input()) for i in range(h)] +B = [] +for i in range(h): +    if "#" in A[i]: +        B.append(A[i]) + + +def rot(X): +    C = [] +    for l in range(len(X[0])): +        C_row = [] +        for m in X: +            C_row.append(m[l]) +        C.append(C_row) +    return C + + +D = rot(B) +E = [] +for i in range(w): +    if "#" in D[i]: +        E.append(D[i]) +F = rot(E) +for f in F: +    print(("".join(f)))