import copy

H,W = list(map(int,input().split()))

A = [list(input().strip()) for _ in range(H)]

while True:

    flag = 0

    for i in range(len(A)-1,-1,-1):

        fr = 0

        for j in range(len(A[0])):

            if A[i][j]=="#":

                fr = 1

                break

        if fr==0:

            B = [[0 for _ in range(len(A[0]))] for _ in range(len(A)-1)]

            for i1 in range(len(A)):

                if i1<i:

                    for j1 in range(len(A[0])):

                        B[i1][j1] = A[i1][j1]

                elif i1>i:

                    for j1 in range(len(A[0])):

                        B[i1-1][j1] = A[i1][j1]

            A = copy.deepcopy(B)

            flag = 1

    for j in range(len(A[0])-1,-1,-1):

        fc = 0

        for i in range(len(A)):

            if A[i][j]=="#":

                fc=1

                break

        if fc==0:

            B = [[0 for _ in range(len(A[0])-1)] for _ in range(len(A))]

            for j1 in range(len(A[0])):

                if j1<j:

                    for i1 in range(len(A)):

                        B[i1][j1] = A[i1][j1]

                elif j1>j:

                    for i1 in range(len(A)):

                        B[i1][j1-1] = A[i1][j1]

            A = copy.deepcopy(B)

            flag = 1

    if flag==0:break

for i in range(len(A)):

    print(("".join(A[i])))
H,W = list(map(int,input().split()))

A = [list(eval(input())) for _ in range(H)]

B = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):

    for j in range(W):

        if A[i][j]=="#":

            B[i][j] = 1

C = []

for i in range(H-1,-1,-1):

    if sum(B[i])==0:

        C.append(i)

B1 = []

for i in range(H):

    if i not in C:

        B1.append(B[i])

C = []

for j in range(W):

    flag = 0

    for i in range(len(B1)):

        if B1[i][j]==1:

            flag = 1

            break

    if flag==0:

        C.append(j)

B2 = []

for i in range(len(B1)):

    row = []

    for j in range(W):

        if j not in C:

            row.append(B1[i][j])

    B2.append(row)

B3 = []

for i in range(len(B2)):

    x = ""

    for j in range(len(B2[i])):

        if B2[i][j]==0:

            x += "."

        else:

            x += "#"

    B3.append(x)

for i in range(len(B3)):

    print((B3[i]))
import copy

H, W = list(map(int, input().split()))
A = [list(input().strip()) for _ in range(H)]
while True:
    flag = 0
    for i in range(len(A) - 1, -1, -1):
        fr = 0
        for j in range(len(A[0])):
            if A[i][j] == "#":
                fr = 1
                break
        if fr == 0:
            B = [[0 for _ in range(len(A[0]))] for _ in range(len(A) - 1)]
            for i1 in range(len(A)):
                if i1 < i:
                    for j1 in range(len(A[0])):
                        B[i1][j1] = A[i1][j1]
                elif i1 > i:
                    for j1 in range(len(A[0])):
                        B[i1 - 1][j1] = A[i1][j1]
            A = copy.deepcopy(B)
            flag = 1
    for j in range(len(A[0]) - 1, -1, -1):
        fc = 0
        for i in range(len(A)):
            if A[i][j] == "#":
                fc = 1
                break
        if fc == 0:
            B = [[0 for _ in range(len(A[0]) - 1)] for _ in range(len(A))]
            for j1 in range(len(A[0])):
                if j1 < j:
                    for i1 in range(len(A)):
                        B[i1][j1] = A[i1][j1]
                elif j1 > j:
                    for i1 in range(len(A)):
                        B[i1][j1 - 1] = A[i1][j1]
            A = copy.deepcopy(B)
            flag = 1
    if flag == 0:
        break
for i in range(len(A)):
    print(("".join(A[i])))

H, W = list(map(int, input().split()))
A = [list(eval(input())) for _ in range(H)]
B = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            B[i][j] = 1
C = []
for i in range(H - 1, -1, -1):
    if sum(B[i]) == 0:
        C.append(i)
B1 = []
for i in range(H):
    if i not in C:
        B1.append(B[i])
C = []
for j in range(W):
    flag = 0
    for i in range(len(B1)):
        if B1[i][j] == 1:
            flag = 1
            break
    if flag == 0:
        C.append(j)
B2 = []
for i in range(len(B1)):
    row = []
    for j in range(W):
        if j not in C:
            row.append(B1[i][j])
    B2.append(row)
B3 = []
for i in range(len(B2)):
    x = ""
    for j in range(len(B2[i])):
        if B2[i][j] == 0:
            x += "."
        else:
            x += "#"
    B3.append(x)
for i in range(len(B3)):
    print((B3[i]))

-import copy - -A = [list(input().strip()) for _ in range(H)] -while True: +A = [list(eval(input())) for _ in range(H)] +B = [[0 for _ in range(W)] for _ in range(H)] +for i in range(H): +    for j in range(W): +        if A[i][j] == "#": +            B[i][j] = 1 +C = [] +for i in range(H - 1, -1, -1): +    if sum(B[i]) == 0: +        C.append(i) +B1 = [] +for i in range(H): +    if i not in C: +        B1.append(B[i]) +C = [] +for j in range(W): -    for i in range(len(A) - 1, -1, -1): -        fr = 0 -        for j in range(len(A[0])): -            if A[i][j] == "#": -                fr = 1 -                break -        if fr == 0: -            B = [[0 for _ in range(len(A[0]))] for _ in range(len(A) - 1)] -            for i1 in range(len(A)): -                if i1 < i: -                    for j1 in range(len(A[0])): -                        B[i1][j1] = A[i1][j1] -                elif i1 > i: -                    for j1 in range(len(A[0])): -                        B[i1 - 1][j1] = A[i1][j1] -            A = copy.deepcopy(B) +    for i in range(len(B1)): +        if B1[i][j] == 1: -    for j in range(len(A[0]) - 1, -1, -1): -        fc = 0 -        for i in range(len(A)): -            if A[i][j] == "#": -                fc = 1 -                break -        if fc == 0: -            B = [[0 for _ in range(len(A[0]) - 1)] for _ in range(len(A))] -            for j1 in range(len(A[0])): -                if j1 < j: -                    for i1 in range(len(A)): -                        B[i1][j1] = A[i1][j1] -                elif j1 > j: -                    for i1 in range(len(A)): -                        B[i1][j1 - 1] = A[i1][j1] -            A = copy.deepcopy(B) -            flag = 1 +            break -        break -for i in range(len(A)): -    print(("".join(A[i]))) +        C.append(j) +B2 = [] +for i in range(len(B1)): +    row = [] +    for j in range(W): +        if j not in C: +            row.append(B1[i][j]) +    B2.append(row) +B3 = [] +for i in range(len(B2)): +    x = "" +    for j in range(len(B2[i])): +        if B2[i][j] == 0: +            x += "." +        else: +            x += "#" +    B3.append(x) +for i in range(len(B3)): +    print((B3[i]))